Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Changed sort parameter.
  • Loading branch information
Pen Pal committed Jun 28, 2018
commit e92ca1d311773ab0c452aa3eb6e9100a0bee66fe
8 changes: 3 additions & 5 deletions chapters/sorting_searching/bubble/code/rust/bubble_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ extern crate rand; // External crate that provides random number generation tool
use rand::{thread_rng, Rng}; // Used for random number generation
use rand::distributions::Uniform; // Used for a uniform distribution

fn bubble_sort(a: &mut Vec<u32>) {
fn bubble_sort(a: &mut [u32]) {
let n = a.len();

for _ in 0..n {
for j in 1..n {
if a[j - 1] > a[j] {
// Swaps values at indices j - 1 and j
let temp = a[j - 1];
a[j - 1] = a[j];
a[j] = temp;
// Swaps values at indicies j - 1 and j
a.swap(j, j - 1);
}
}
}
Expand Down