Created
February 21, 2018 09:00
-
-
Save visparashar/29551278650285844e6a161dc274058f 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 RotateByReversal { | |
public static void main(String[] args) { | |
int arr[] ={1,2,3,4,5,6,7}; | |
RotateByReversal rr = new RotateByReversal(); | |
rr.reverse(arr, 0, 1); | |
rr.reverse(arr, 2, 6); | |
rr.reverse(arr, 0, 6); | |
for(int i =0;i<arr.length;i++){ | |
System.out.println(arr[i]); | |
} | |
} | |
public void reverse(int[] a , int start , int end){ | |
while(start<end){ | |
int temp = a[start]; | |
a[start] = a[end]; | |
a[end] = temp; | |
end--; | |
start++; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment