Skip to content

Instantly share code, notes, and snippets.

@visparashar
Created February 21, 2018 09:00
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/29551278650285844e6a161dc274058f to your computer and use it in GitHub Desktop.
Save visparashar/29551278650285844e6a161dc274058f to your computer and use it in GitHub Desktop.
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