Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,26 @@
|
|||
fn gnome_sort<T: PartialOrd>(a: &mut [T]) {
|
||||
let len = a.len();
|
||||
let mut i: usize = 1;
|
||||
let mut j: usize = 2;
|
||||
while i < len {
|
||||
if a[i - 1] <= a[i] {
|
||||
// for descending sort, use >= for comparison
|
||||
i = j;
|
||||
j += 1;
|
||||
} else {
|
||||
a.swap(i - 1, i);
|
||||
i -= 1;
|
||||
if i == 0 {
|
||||
i = j;
|
||||
j += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut v = vec![10, 8, 4, 3, 1, 9, 0, 2, 7, 5, 6];
|
||||
println!("before: {:?}", v);
|
||||
gnome_sort(&mut v);
|
||||
println!("after: {:?}", v);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue