-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsertion.js
More file actions
44 lines (39 loc) · 1.2 KB
/
insertion.js
File metadata and controls
44 lines (39 loc) · 1.2 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
39
40
41
42
43
44
async function insertion(){
console.log('In insertion()');
const ele = document.querySelectorAll(".bar");
// color
ele[0].style.background = 'green';
for(let i = 1; i < ele.length; i++){
console.log('In ith loop');
let j = i - 1;
let key = ele[i].style.height;
// color
ele[i].style.background = 'blue';
await waitforme(delay);
while(j >= 0 && (parseInt(ele[j].style.height) > parseInt(key))){
console.log('In while loop');
// color
ele[j].style.background = 'blue';
ele[j + 1].style.height = ele[j].style.height;
j--;
await waitforme(delay);
// color
for(let k = i; k >= 0; k--){
ele[k].style.background = 'green';
}
}
ele[j + 1].style.height = key;
// color
ele[i].style.background = 'green';
}
}
const inSortbtn = document.querySelector(".insertionSort");
inSortbtn.addEventListener('click', async function(){
disableSortingBtn();
disableSizeSlider();
disableNewArrayBtn();
await insertion();
enableSortingBtn();
enableSizeSlider();
enableNewArrayBtn();
});