modified the while function to use the range based for loops

This commit is contained in:
jellyfishsh 2025-04-12 14:51:43 -07:00
parent a8623726ec
commit bc7afc2dc3

View File

@ -53,33 +53,31 @@ fn randomize_vector (vector : &mut Vec<i32>, size : u32) {
#[allow(dead_code)]
fn selection_sort(vector : &mut [i32]) {
//Creates the anonymous indexing value
let mut i : usize = 0;
while i < vector.len() {
// Outer loop
for i in 0..vector.len() {
//Keep track of the greatest value
let mut max_value = vector[i];
let mut max_index = i;
//Creates the anonymous indexing value
let mut j : usize = i;
while j < vector.len() {
// Inner loop
for j in i..vector.len() {
if vector[j] > max_value {
//We make this the new greatest
max_value = vector[j];
max_index = j;
}
j += 1;
}
//Swap the values
let temp = vector[i];
vector[i] = max_value;
vector[max_index] = temp;
i += 1;
}
}