Created
December 6, 2014 14:20
-
-
Save rylev/5a52f80fea13c3f8fc9d to your computer and use it in GitHub Desktop.
Bubble Sort Written In Rust
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 bubble_sort(numbers: &Vec<i64>, compare_fn: |i64, i64| -> i64) -> Vec<i64> { | |
let mut temp; | |
let mut target = numbers.clone(); | |
let length = numbers.len(); | |
for _ in range(0, length) { | |
for j in range(0, length - 1) { | |
if compare_fn(target[j], target[j+1]) > 0 { | |
temp = target[j+1]; | |
target[j+1] = target[j]; | |
target[j] = temp; | |
} | |
} | |
} | |
target | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment