-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselectionSort.js
More file actions
38 lines (37 loc) · 1.08 KB
/
selectionSort.js
File metadata and controls
38 lines (37 loc) · 1.08 KB
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
let f1,f2,ha,hb;
async function selectionSort(){
for(let i=0;i<sze-1;i++){
let pos=i;
f1=children.item(i);
f1.style.backgroundColor="purple";
for(let j=i+1;j<sze;j++){
f2=children.item(j);
f2.style.backgroundColor="purple";
await new Promise(resolve => setTimeout(() => {resolve()},speed));
if(height[j]<height[pos]){
pos=j;
}
f2.style.backgroundColor="red";
}
let tmp=height[i];
height[i]=height[pos];
height[pos]=tmp;
f2=children.item(pos);
ha=f1.style.height;
hb=f2.style.height;
f1.style.height=hb;
f2.style.height=ha;
f1.style.backgroundColor="green";
}
f1=children.item(sze-1);
f1.style.backgroundColor="green";
}
document.getElementById("selectionSort").addEventListener("click",async function(){
disableSortingButton();
disableNewArrayBtn();
disableSizeSlider();
await selectionSort();
enableSortingBtn();
enableNewArrayBtn();
enableSizeSlider();
});