pub fn cycle_sort(arr: &mut [i32]) {
    for cycle_start in 0..arr.len() {
        let mut item = arr[cycle_start];
        let mut pos = cycle_start;
        for i in arr.iter().skip(cycle_start + 1) {
            if *i < item {
                pos += 1;
            }
        }
        if pos == cycle_start {
            continue;
        }
        while item == arr[pos] {
            pos += 1;
        }
        std::mem::swap(&mut arr[pos], &mut item);
        while pos != cycle_start {
            pos = cycle_start;
            for i in arr.iter().skip(cycle_start + 1) {
                if *i < item {
                    pos += 1;
                }
            }
            while item == arr[pos] {
                pos += 1;
            }
            std::mem::swap(&mut arr[pos], &mut item);
        }
    }
}
// sorts with the minimum number of rewrites. Runs through all values in the array, placing them in their correct spots. O(n^2).
sorts with the minimum number of rewrites. Runs through all values in the array, placing them in their correct spots.
sorts with the minimum number of rewrites . Runs through all values in the array placing them in their correct spots .
pub fn cycle_sort(arr: &mut [i32]) {
    for cycle_start in 0..arr.len() {
        let mut item = arr[cycle_start];
        let mut pos = cycle_start;
        for i in arr.iter().skip(cycle_start + 1) {
            if *i < item {
                pos += 1;
            }
        }
        if pos == cycle_start {
            continue;
        }
        while item == arr[pos] {
            pos += 1;
        }
        std::mem::swap(&mut arr[pos], &mut item);
        while pos != cycle_start {
            pos = cycle_start;
            for i in arr.iter().skip(cycle_start + 1) {
                if *i < item {
                    pos += 1;
                }
            }
            while item == arr[pos] {
                pos += 1;
            }
            std::mem::swap(&mut arr[pos], &mut item);
        }
    }
}
pub fn cycle_sort ( arr : & mut [ i32 ] ) { for cycle_start in 0 .. arr . len ( ) { let mut item = arr [ cycle_start ] ; let mut pos = cycle_start ; for i in arr . iter ( ) . skip ( cycle_start + 1 ) { if * i < item { pos += 1 ; } } if pos == cycle_start { continue ; } while item == arr [ pos ] { pos += 1 ; } std :: mem :: swap ( & mut arr [ pos ] , & mut item ) ; while pos != cycle_start { pos = cycle_start ; for i in arr . iter ( ) . skip ( cycle_start + 1 ) { if * i < item { pos += 1 ; } } while item == arr [ pos ] { pos += 1 ; } std :: mem :: swap ( & mut arr [ pos ] , & mut item ) ; } } }
sorts with the minimum number of rewrites.
sorts with the minimum number of rewrites .
arr
&mut [i32]
arr
&mut [i32]