Skip to content

Instantly share code, notes, and snippets.

@fatihgokce
Created March 3, 2020 17:24
Show Gist options
  • Save fatihgokce/8d39126f5d48c7459507989791a42ca9 to your computer and use it in GitHub Desktop.
Save fatihgokce/8d39126f5d48c7459507989791a42ca9 to your computer and use it in GitHub Desktop.
fn rotate_one(arr: &mut [i32]) {
//arr[1] = 10;
let c=arr.len();
let first=arr[0];
let mut i=1;
while i<c{
arr[i-1]=arr[i];
i+=1;
}
arr[c-1]=first;
}
fn rotate(arr: &mut [i32],r:i32){
for n in 0..r{
rotate_one(arr);
}
}
fn main() {
let mut arr: [i32;6] = [1, 2, 3, 4,5,6];
rotate(&mut arr,6);
println!("this is {:?}", arr);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment