-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbubble_sort.js
39 lines (31 loc) · 1.3 KB
/
bubble_sort.js
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
function Bubble()
{
//Setting Time complexities
document.getElementById("Time_Worst").innerText="O(N^2)";
document.getElementById("Time_Average").innerText="Θ(N^2)";
document.getElementById("Time_Best").innerText="Ω(N)";
//Setting Space complexity
document.getElementById("Space_Worst").innerText="O(1)";
c_delay=0;//This control the delay btween visualization process
for(var i=0;i<array_size-1;i++)
{
for(var j=0;j<array_size-i-1;j++)
{
div_update(divs[j],div_sizes[j],"yellow");//Color update
if(div_sizes[j]>div_sizes[j+1])
{
div_update(divs[j],div_sizes[j], "red");//Color update
div_update(divs[j+1],div_sizes[j+1], "red");//Color update
var temp=div_sizes[j];
div_sizes[j]=div_sizes[j+1];
div_sizes[j+1]=temp;
div_update(divs[j],div_sizes[j], "red");//Height update
div_update(divs[j+1],div_sizes[j+1], "red");//Height update
}
div_update(divs[j],div_sizes[j], "blue");//Color updat
}
div_update(divs[j],div_sizes[j], "green");//Color update
}
div_update(divs[0],div_sizes[0], "green");//Color update
enable_buttons();
}