cycle_sort

Function cycle_sort 

Source
pub fn cycle_sort<T>(slice: &mut [T]) -> usize
where T: Ord,
Expand description

Sorts a slice using the elements’ natural ordering and returns the number of writes made.

§Examples

let mut a = [1, 4, 1, 5, 9, 2];
let     w = cycle_sort(&mut a);

assert_eq!(a, [1, 1, 2, 4, 5, 9]);
assert_eq!(w, 5);