Skip to content

Instantly share code, notes, and snippets.

@rylev rylev/bubble.rs
Created Dec 6, 2014

Embed
What would you like to do?
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
You can’t perform that action at this time.