Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int[] reverseOrder(int[] array) {
- return swap(array, array.length, 0);
- }
- public static int[] swap(int[] array, int length, int pos) {
- if (pos * 2 <= length) {
- int help;
- help = array[pos];
- array[pos] = array[length - 1 - pos];
- array[length - 1 - pos] = help;
- swap(array, length, pos + 1);
- }
- return array;
- }
- public static int[][] myreverseOrder(int[][] array) {
- return reverseIt(array, false, 0);
- }
- public static int[][] reverseIt(int[][] array, boolean isReversed, int pos) {
- if (pos * 2 <= array.length + 1) {
- if (isReversed) {
- array[pos] = reverseOrder(array[pos]);
- return reverseIt(array, true, pos + 1);
- } else {
- Collections.reverse(Arrays.asList(array));
- return reverseIt(array, true, pos);
- }
- } else {
- return array;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment