Function rudac::algo::sort::quick_sort_with[][src]

pub fn quick_sort_with<T, F>(slice: &mut [T], compare: &F) where
    F: Fn(&T, &T) -> Ordering
Expand description

Quicksort is an efficient sorting algorithm

Arguments

  • slice: slice of data to be sorted
  • compare: custom comparison closure

Examples

use rudac::algo::sort::quick_sort_with;
 
// consider vector of 2d points
let mut vec = vec![(1, 10), (2,6), (3,1), (3,4), (4,2), (5,3), (6,7), (8,9), (9,8), (10,5)];
 
// sort based on y axis
quick_sort_with(&mut vec, &|x1,x2| {x1.1.cmp(&x2.1)});
 
assert_eq!(vec, vec![(3,1), (4,2), (5,3), (3,4), (10,5), (2,6), (6,7), (9,8), (8,9), (1,10)]);