-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathreverseArray.java
More file actions
45 lines (35 loc) · 1018 Bytes
/
reverseArray.java
File metadata and controls
45 lines (35 loc) · 1018 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package Programs.Recursion;
public class reverseArray{
public static void swap(int[] arr, int i, int j){
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
public static void reverse(int[] arr, int l, int r){
if(l>=r){
return;
}
swap(arr, l, r);
reverse(arr, l+1, r-1);
}
public static void print(int[] arr){
for(int i=0; i<arr.length; i++){
System.out.print(arr[i]+" ");
}
}
public static void main(String[] args){
int[] arr = {1,2,3,4,5,6,7,8,9,10};
int n = 10;
int l = 0;
int r = n-1;
reverse(arr, l, r);
print(arr);
}
}
<<<<<<< HEAD
// This article is Contributed by Himanshu Jha.
// Connect with me on linkedin https://www.linkedin.com/in/himanshujhaa/
=======
This article is Contributed by Himanshu Jha.
Connect with me on linkedin https://www.linkedin.com/in/himanshujhaa/
>>>>>>> ac2d3cc604ad9612702aeac09180b1fa93dd5fec