-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsertion_sort.js
43 lines (35 loc) · 1.12 KB
/
insertion_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
40
41
42
43
function Insertion()
{
c_delay = 0;
for(var j = 0;j<array_size;j++)
{
div_update(divs[j],div_sizes[j],"yellow");
var key = div_sizes[j];
var i = j-1;
while(i >= 0 && div_sizes[i] > key)
{
div_update(divs[i],div_sizes[i],"red");//Color update
div_update(divs[i+1],div_sizes[i+1],"red");//Color update
div_sizes[i+1] = div_sizes[i];
div_update(divs[i],div_sizes[i],"red");
div_update(divs[i+1],div_sizes[i+1],"red");
div_update(divs[i],div_sizes[i],"blue");
if(i==(j-1))
{
div_update(divs[i+1],div_sizes[i+1],"yellow");//Color update
}
else
{
div_update(divs[i+1],div_sizes[i+1],"blue");//Color update
}
i-=1;
}
div_sizes[i+1] = key;
for(var t=0;t<j;t++)
{
div_update(divs[t],div_sizes[t],"green");//Color update
}
}
div_update(divs[j-1],div_sizes[j-1],"green");//Color update
enable_buttons();
}