-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
52 lines (42 loc) · 796 Bytes
/
script.js
File metadata and controls
52 lines (42 loc) · 796 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var arr = [];
setupArray();
paintGraph();
//var bubbleHandle = setInterval(bubbleSort,10);
//swap(0,1);
//swap(1,0);
//swap(2,0);
document.getElementById("bubbleBTN").addEventListener("click", start);
var bubbleSorter;
function start(){
bubbleSorter = setInterval(bubbleSort,0);
}
var i = 0;
var sorted = false,swapMade = false;
var temp =0;
var last = 200;
function bubbleSort(){
//while(!sorted){
//console.log(arr);
if(arr[i] > arr[i+1]){
temp = arr[i];
arr[i] = arr[i+1];
arr[i+1] = temp;
swapMade = true;
swap(i,i+1);
}
i++;
if(i >= last){
last = i-1;
//console.log(last);
i=0;
if(swapMade == true){
sorted = false;
swapMade = false;
}else {
console.log(arr);
sorted = true;
clearInterval(bubbleSorter)
}
}
//}
}