forked from Annex5061/java-algorithms
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBubbleSortAlgorithmEx.java
More file actions
Latest commit
32 lines (30 loc) · 970 Bytes
/
Copy pathBubbleSortAlgorithmEx.java
File metadata and controls
32 lines (30 loc) · 970 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
publicclassBubbleSortAlgorithmEx {
publicstaticvoidmain(String[] args) {
int[] array ={6,10,1,8,7,5,2};
System.out.println("Bubble Sort Algorithm");
System.out.println("----------------------");
System.out.println("All elements in the array : ");
for (intj : array) {
System.out.print(j + " ");
}
System.out.println();
bubbleSort(array);
System.out.println("Sorted Array : ");
for (intj : array) {
System.out.print(j + " ");
}
}
staticvoidbubbleSort(int[] array) {
intn = array.length;
inttemp = 0;
for(inti=0; i < n; i++){
for(intj=1; j < (n-i); j++){
if(array[j-1] > array[j]){
temp = array[j-1];
array[j-1] = array[j];
array[j] = temp;
}
}
}
}
}