Ex:- [ 1, 2, 3, 4, 5] after reversing [ 5, 4, 3, 2, 1]
Here, " in place " means you can't take another array to reverse.
Java
1 2 3 4 5 6 7 8 9 10 11 12 | public class ArrayReverse{ public static void main(String []args){ int[] arr = {1, 2, 3, 4, 5, 6}; for(int i=0; i<arr.length/2; i++){ int temp = arr[i]; arr[i] = arr[arr.length-i-1]; arr[arr.length-i-1] = temp; } for(int x:arr) System.out.print(x+" "); } } |
Python
given_list = [1, 2, 3, 4, 5, 6] given_list.reverse() print(given_list) |