Skip to content

Commit 530a9f0

Browse files
authored
Create Reverse_Array.java
1 parent 77944dc commit 530a9f0

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

Recursion/Reverse_Array.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//Recursion Revison :)
2+
// Reverse Array :-
3+
import java.util.*;
4+
5+
public class Main
6+
{
7+
public static void main(String[] args) {
8+
//System.out.println("Hello World");
9+
int[] arr = new int[]{3,4,7,8,2};
10+
reverseArr(0,arr);
11+
12+
for(int ele : arr){
13+
System.out.print(ele+" ");
14+
}
15+
16+
}
17+
18+
public static void reverseArr(int indx ,int[] arr){
19+
//Base Case::
20+
if(indx==arr.length){
21+
return;
22+
}
23+
int ele = arr[indx];
24+
//Hypothese
25+
reverseArr(indx+1,arr);
26+
insert(ele,indx,arr);
27+
}
28+
29+
public static void insert(int ele,int indx,int[] arr){
30+
if(indx<0){
31+
return;
32+
}
33+
arr[arr.length-(indx+1)] = ele;
34+
return ;
35+
36+
}
37+
}

0 commit comments

Comments
 (0)