Created
February 21, 2018 08:57
-
-
Save visparashar/6edd59f07f57f5f154b4bc2a5664d628 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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