Skip to content

Commit 1f7d457

Browse files
sorted array checking using recursion
1 parent 559bb29 commit 1f7d457

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

Recursion/SortedOrNot.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
public class SortedOrNot {
2+
3+
public static void main(String[] args) {
4+
int arr [] = {1,3,4,5,6,-1};
5+
boolean result = isSorted(arr,arr.length);
6+
if(result){
7+
System.out.println("Your Array is sorted");
8+
}else{
9+
System.out.println("Your Array is not sorted");
10+
}
11+
}
12+
13+
static boolean isSorted(int []arr,int index ){
14+
15+
if(index == 0 || index ==1){
16+
return true;
17+
}
18+
19+
return arr[index-1] >= arr[index-2] && isSorted(arr, index-1);
20+
21+
}
22+
}

test.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)