[][src]Function buldak::counting::sort

pub fn sort<T, Max>(
    array: &mut [T],
    max: Max,
    signed: bool
) -> Result<(), String> where
    T: TryInto<isize> + TryFrom<isize> + Clone,
    <T as TryInto<isize>>::Error: Debug,
    <T as TryFrom<isize>>::Error: Debug,
    Max: TryInto<isize>,
    <Max as TryInto<isize>>::Error: Debug

Sort in ascending order using a counting sort algorithm.

The parameter 'max' is the absolute maximum value of the received array. Any elements beyond this value will result in an error.

The parameter 'signed' chooses whether to support negative numbers. When using only natural numbers, it is twice as efficient to set signed to false. If signed is set to false and the array contains negative elements, an error occurs.

let mut nums = [1, 4, 2, 3, 5, 111, 234, 21, 13];
counting::sort(&mut nums, 300, true);
assert_eq!(nums, [1, 2, 3, 4, 5, 13, 21, 111, 234]);