-
Notifications
You must be signed in to change notification settings - Fork 6
/
bubbleSORT.java
37 lines (23 loc) · 946 Bytes
/
bubbleSORT.java
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
34
35
36
37
/**
*
* @author Arl Kheem Rey Galario
*/
public class bubbleSORT {
public static void main(String [] args){
int i, j , swap;
int [] arr = {3,2,1,5,1,2,6,6,8,4,9,12 ,0 ,34, 34,6,1,100}; // array to be sorted
for(i = 0; i < arr.length; i ++){
for(j = 0; j < arr.length - 1 ;j++){
if(arr[j] > arr[j+1]){
swap = arr[j]; // place the bigger number to swap
arr[j] = arr[j+1]; // place the smaller number
arr[j+1] = swap;
}
}
}
//Display the sorted array
for(int x = 0 ; x < arr.length ; x ++){
System.out.print(arr[x] + ", ");
}
}
}