[−][src]Function algos::sort::bubble
pub fn bubble<T: PartialOrd, C: Fn(&T, &T) -> bool>(v: &mut [T], cmp: &C)
Bubble Sort: Sort v
slice according to the way you define the cmp
parameter.
This sort is stable.
Case | Time complexity | Space complexity |
---|---|---|
Best: | Ω(n) | |
Avrg: | Θ(n²) | |
Worst: | O(n²) | O(1) |
Example
use algos::sort; let mut v = [9, 3, 5, 7, 8, 7]; // Crescent sorting sort::bubble(&mut v, &|v, b| v < b);