Skip to content

Commit a506dca

Browse files
authored
Create RecursiveBubbleSort.java
1 parent b3024df commit a506dca

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
public class Program {
2+
public static void main(String[] args) {
3+
int[] arr = bubbleSort(new int[] { 64, 34, 25, 12, 22, 11, 90 });
4+
for (int i = 0; i < arr.length; System.out.println(arr[i++]))
5+
;
6+
7+
}
8+
9+
public static int[] bubbleSort(int[] arr) {
10+
for (int i = 0; i < arr.length; i++) {
11+
try {
12+
int num = arr[i];
13+
if (arr[i + 1] < num) {
14+
arr[i] = arr[i + 1];
15+
arr[i + 1] = num;
16+
bubbleSort(arr);
17+
}
18+
} catch (IndexOutOfBoundsException e) {
19+
continue;
20+
}
21+
}
22+
return arr;
23+
}
24+
}

0 commit comments

Comments
 (0)