forked from marktennyson/Java-programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBubbleSorter.java
More file actions
34 lines (33 loc) · 877 Bytes
/
Copy pathBubbleSorter.java
File metadata and controls
34 lines (33 loc) · 877 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
34
class BSorter{
int[] Arr;
int arrLen, temp2, temp1;
BSorter(int[] Arr){
this.Arr = Arr;
this.arrLen = Arr.length;
}
void sort(){
for (int i = 0; i < arrLen-1; i++){
for (int j = 0; j < arrLen-i-1; j++){
if(this.Arr[j] > this.Arr[j+1]){
this.temp1 = Arr[j];
this.temp2 = Arr[j+1];
this.Arr[j] = this.temp2;
this.Arr[j+1] = this.temp1;
}
}
}
}
void display(){
for (int i = 0; i < this.arrLen; i++) {
System.out.println(this.Arr[i]);
}
}
}
public class BubbleSorter{
public static void main(String[] args){
int[] arr = {12,23,34,22,87,45};
BSorter sorter = new BSorter(arr);
sorter.sort();
sorter.display();
}
}