Skip to content

Instantly share code, notes, and snippets.

@NaN1235123
Last active February 29, 2024 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save NaN1235123/65a1b04b8d692c466b6d7eeb412e07ec to your computer and use it in GitHub Desktop.
Save NaN1235123/65a1b04b8d692c466b6d7eeb412e07ec to your computer and use it in GitHub Desktop.
fn main() {
fn something(array: &mut Vec<i32>) {
let mut length = array.len();
let mut swapped;
while length != 0 {
swapped = 0;
for index in 1..length {
if array[index] == -1 {
array.swap(index -1, index);
swapped = index;
}
}
length = swapped;
}
}
let mut some_arr = vec![1,1,1,1,1,-1,-1,-1,1,-1];
something(& mut some_arr);
println!("{:?}", some_arr);
// [-1, -1, -1, -1, 1, 1, 1, 1, 1, 1]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment