Function sorts::bubble_sort::bubble_sort

source ·
pub fn bubble_sort<T: PartialOrd>(sequence: &mut [T])
Expand description

Sorts a slice in-place using bubble sort.

Examples

To sort a vector

let mut slice = vec![3,2,1,4];
sorts::bubble_sort(&mut slice);
assert_eq!(slice, &[1,2,3,4]);

All kinds of slices can be sorted as long as they implement PartialOrd.

let mut strings = vec!["rustc", "cargo", "rustup"];
sorts::bubble_sort(&mut strings);
assert_eq!(strings, &["cargo", "rustc", "rustup"]);