pcclark4 / cggml

A general algorithms library written in ANSI C.
1 stars 0 forks source link

Implement sort_cycle #1

Closed pcclark4 closed 4 years ago

pcclark4 commented 4 years ago

https://en.wikipedia.org/wiki/Cycle_sort https://rosettacode.org/wiki/Sorting_algorithms/Cycle_sort#C

Keep in mind the "swap" that happens isn't an in-place swap within the list. It's a swap with a tmp variable, and this is required for the algorithm to work. This is why we need the caller to pass us a pointer to store the tmp value in. Otherwise we could just do a simple byte-wise swap.