Created
January 2, 2020 09:39
-
-
Save aita/79682019eeb74fb1f8c63900cd0b1762 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fn gnome_sort<T: PartialOrd>(v: &mut [T]) { | |
| let len = v.len(); | |
| let mut i = 1; | |
| while i < len { | |
| if v[i - 1] <= v[i] { | |
| i += 1; | |
| } else { | |
| v.swap(i - 1, i); | |
| i -= 1; | |
| if i == 0 { | |
| i += 1; | |
| } | |
| } | |
| } | |
| } | |
| fn main() { | |
| let mut v = [5, 1, 4, 2, 6, 3]; | |
| gnome_sort(&mut v); | |
| println!("{:?}", v); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment