-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathBubbleSort.java
More file actions
33 lines (28 loc) · 856 Bytes
/
BubbleSort.java
File metadata and controls
33 lines (28 loc) · 856 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
public class BubbleSort {
static void bubbleSort(int[] list) {
int n = list.length;
int temp = 0;
for(int i=0; i < n; i++){
for(int j=1; j < (n-i); j++){
if(list[j-1] > list[j]){
temp = list[j-1];
list[j-1] = list[j];
list[j] = temp;
}
}
}
}
public static void main(String[] args) {
int list[] ={1,10,500,3,55,301,12,45,23,32,100};
System.out.println("Unsorted Array");
for(int i=0; i < list.length; i++){
System.out.print(list[i] + " ");
}
System.out.println();
bubbleSort(list);
System.out.println("Sorted Array");
for(int i=0; i < list.length; i++){
System.out.print(list[i] + " ");
}
}
}