Skip to content

Commit 8f4dc98

Browse files
committed
Bubble Sorting
1 parent 02f7fbe commit 8f4dc98

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.algorithm.sorting;
2+
3+
import java.util.Arrays;
4+
5+
public class BubbleSort {
6+
7+
public static void main(String[] args) {
8+
int array[] ={3,60,35,2,45,320,5};
9+
System.out.println("Before Sorting :: "+Arrays.toString(array));
10+
bubbleSort(array);
11+
System.out.println("After Sorting :: "+Arrays.toString(array));
12+
}
13+
14+
public static void bubbleSort(int array[]){
15+
int n = array.length;
16+
for(int i=0;i<n-1;i++)
17+
for(int j=0;j<n-i-1;j++)
18+
if(array[j] > array[j+1]){
19+
int temp = array[j];
20+
array[j] = array[j+1];
21+
array[j+1] = temp;
22+
}
23+
}
24+
25+
}

0 commit comments

Comments
 (0)