Skip to content

Commit 121bdd4

Browse files
authored
Create Simple Array Sorting.java
1 parent 2104656 commit 121bdd4

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import java.util.*;
2+
3+
public class Main
4+
{
5+
static boolean isSorted(int[] arr, int size){
6+
7+
//base case
8+
9+
if(size == 0 || size == 1){
10+
return true;
11+
}
12+
13+
// processing
14+
15+
if(arr[size - 1] < arr[size - 2]){
16+
return false;
17+
}
18+
19+
// recursive call
20+
return isSorted(arr, size - 1);
21+
}
22+
23+
public static void main(String[] args) {
24+
25+
int[] arr = {45, 674, 34, 65, 4, 56};
26+
27+
// int[] arr = {0, 1, 2, 3, 4, 5};
28+
int size = 6;
29+
30+
boolean ans = isSorted(arr, size);
31+
32+
if(ans){
33+
System.out.println("Array Is Sorted");
34+
} else {
35+
System.out.println("Array Is Not Sorted");
36+
}
37+
38+
}
39+
}

0 commit comments

Comments
 (0)