Skip to content

Instantly share code, notes, and snippets.

@rylev
Created December 6, 2014 14:20
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rylev/5a52f80fea13c3f8fc9d to your computer and use it in GitHub Desktop.
Save rylev/5a52f80fea13c3f8fc9d to your computer and use it in GitHub Desktop.
Bubble Sort Written In Rust
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