Skip to content

Commit 25af99b

Browse files
Merge pull request #452 from siddharth3108/Recursivebubblesort.java
Create Recursivebubblesort.java
2 parents 31efe23 + fd2be35 commit 25af99b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import java.util.Arrays;
2+
public class Demo{
3+
static void bubble_sort(int my_arr[], int len_arr){
4+
if (len_arr == 1)
5+
return;
6+
for (int i=0; i<len_arr-1; i++)
7+
if (my_arr[i] > my_arr[i+1]){
8+
int temp = my_arr[i];
9+
my_arr[i] = my_arr[i+1];
10+
my_arr[i+1] = temp;
11+
}
12+
bubble_sort(my_arr, len_arr-1);
13+
}
14+
public static void main(String[] args){
15+
int my_arr[] = {45, 67, 89, 31, 63, 0, 21, 12};
16+
bubble_sort(my_arr, my_arr.length);
17+
System.out.println("The array after implementing bubble sort is ");
18+
System.out.println(Arrays.toString(my_arr));
19+
}
20+
}

0 commit comments

Comments
 (0)