fn bubble_sort<T: PartialOrd>(list: &mut Vec<T>) -> &Vec<T> {
for _i in 0..list.len() {
for x in 0..list.len() - 1 {
if list[x] > list[x + 1] {
list.swap(x, x + 1);
}
}
}
list
}
fn main() {
let mut list = vec![1, 4, 3, 7, 2];
bubble_sort(&mut list);
println!("i32类型排序: {:?}", list);
let mut list1 = vec!['e', 'f', 'a', 'z', 'A', 'C'];
bubble_sort(&mut list1);
println!("char类型排序: {:?}", list1);
let mut list2 = vec![
String::from("Alice"),
String::from("David"),
String::from("Tom"),
String::from("Jack"),
];
bubble_sort(&mut list2);
println!("String类型排序: {:?}", list2);
}
-
Notifications
You must be signed in to change notification settings - Fork 0
xubin0813/bubble-sort
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
No description, website, or topics provided.
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published