Created
February 13, 2016 12:22
-
-
Save deximat/f3bbcb2e36058a6ca0db 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
private static void rotate(int[] array, int r) { | |
reverse(array, 0, array.length); | |
reverse(array, 0, r); | |
reverse(array, r + 1, array.length); | |
} | |
private static void reverse(int[] array, int start, int end) { | |
while (start < end) { | |
swap(array, start, end); | |
start++; | |
end--; | |
} | |
} | |
private static void swap(int[] array, int start, int end) { | |
int tmp = array[start]; | |
array[start] = array[end]; | |
array[end] = tmp; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment