You are viewing a single comment's thread. Return to all comments →
Rust Solution:
fn insertionSort1(n: i32, arr: &[i32]) { let mut vector: Vec<i32> = vec![arr[0]]; for i in 1..n { vector.push(arr[i as usize]); } let mut index = (n - 1) as usize; let temp = arr[index]; while index.checked_sub(1) != None && vector[index - 1] > temp { vector[index] = arr[index - 1]; index -= 1; for ele in &vector { print!("{} ", ele); } print!("\n"); } vector[index] = temp; for ele in &vector { print!("{} ", ele); } print!("\n"); }
Seems like cookies are disabled on this browser, please enable them to open this website
Insertion Sort - Part 1
You are viewing a single comment's thread. Return to all comments →
Rust Solution: