Skip to content

Instantly share code, notes, and snippets.

@visparashar
Created February 21, 2018 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save visparashar/6edd59f07f57f5f154b4bc2a5664d628 to your computer and use it in GitHub Desktop.
Save visparashar/6edd59f07f57f5f154b4bc2a5664d628 to your computer and use it in GitHub Desktop.
public class RotateByOneArrayRotating {
public static void main(String[] args) {
int a[] ={1,2,3,4,5,6,7};
int d=2;
RotateByOneArrayRotating r = new RotateByOneArrayRotating();
r.rotateLeft(a, d, 7);
for(int i =0;i<a.length;i++){
System.out.println(a[i]);
}
}
public void rotateLeft(int[] arr ,int d , int n){
for(int i =0;i<d;i++){
rotatLeftByOne(arr,n);
}
}
public void rotatLeftByOne(int[] arr ,int n){
int i ;
int temp;
temp =arr[0];
for(i =0;i<n-1;i++){
arr[i]=arr[i+1];
}
arr[i]=temp;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment