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