-
Notifications
You must be signed in to change notification settings - Fork 0
/
bubble_sort.js
33 lines (25 loc) · 890 Bytes
/
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
function Bubble()
{
c_delay = 0;
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[i],"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");
div_update(divs[j+1],div_sizes[j+1],"red");
}
div_update(divs[j],div_sizes[j],"blue");
}
div_update(divs[j],div_sizes[j],"green");
}
div_update(divs[0],div_sizes[0],"green");
enable_buttons();
}