-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBubble.java
49 lines (32 loc) · 980 Bytes
/
Bubble.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
38
39
40
41
42
43
44
45
46
47
48
49
public class Bubble extends Thread{
int[] a;
public Bubble(int[] ref){
a = ref;
}
public void sleep(){
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void run() {
sleep();
int j;
boolean flag = true; // set flag to true to begin first pass
int temp; //holding variable
while ( flag ) {
flag = false; //set flag to false awaiting a possible swap
for(j=0; j < a.length -1; j++ ){
if ( a[ j ] < a[j+1] ){ // change to > for ascending sort
temp = a[ j ]; //swap elements
a[ j ] = a[ j+1 ];
a[ j+1 ] = temp;
flag = true; //shows a swap occurred
sleep();
}
}
}
}
}