Created
January 6, 2018 20:24
-
-
Save kevinquinnyo/d9beead2baa17a4da1e22c59c0f4dde6 to your computer and use it in GitHub Desktop.
Revisions
-
kevinquinnyo created this gist
Jan 6, 2018 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ fn main() { let mut array: [i32; 5] = [5, 6, 3, 2, 8]; let sorted = bubble_sort(array); for x in &sorted { println!("{0}", x); } assert_eq!(sorted, [2, 3, 5, 6, 8], "Failed to sort array."); } fn bubble_sort(mut array: [i32; 5]) -> [i32; 5] { for i in 0..array.len() { for j in 0..array.len() - i - 1 { if array[j] > array[j + 1] { let tmp = array[j]; array[j] = array[j + 1]; array[j + 1] = tmp; } } } return array; }