-
Notifications
You must be signed in to change notification settings - Fork 0
/
selection_sort.js
46 lines (38 loc) · 1.28 KB
/
selection_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
44
45
46
function Selection_sort()
{
c_delay = 0;
for(var i=0 ;i<array_size;i++)
{
div_update(divs[i],div_sizes[i],"red");
index_min = i;
for(var j = i+1;j<array_size;j++)
{
div_update(divs[j],div_sizes[j],"yellow");
if(div_sizes[j] < div_sizes[index_min])
{
if(index_min != i)
{
div_update(divs[index_min],div_sizes[index_min],"blue");
}
index_min = j;
div_update(divs[index_min],div_sizes[index_min],"red")
}
else
{
div_update(divs[j],div_sizes[j],"blue");//Color update
}
}
if(index_min!=i)
{
var temp=div_sizes[index_min];
div_sizes[index_min]=div_sizes[i];
div_sizes[i]=temp;
div_update(divs[index_min],div_sizes[index_min],"red");//Height update
div_update(divs[i],div_sizes[i],"red");//Height update
div_update(divs[index_min],div_sizes[index_min],"blue");//Color update
}
div_update(divs[i],div_sizes[i],"green");//Color update
}
div_update(divs[i],div_sizes[i],"green");
enable_buttons();
}