-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbubbleSort.js
More file actions
34 lines (28 loc) · 1.11 KB
/
Copy pathbubbleSort.js
File metadata and controls
34 lines (28 loc) · 1.11 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
const bubbleSort = async () => {
let bars = document.querySelectorAll('.bar');
for(let i = 0; i < bars.length -1; i++) {
for(let j = 0; j < bars.length-i-1; j++){
bars[j].style.background = 'blue';
bars[j+1].style.background = 'blue';
if(parseInt(bars[j].style.height) > parseInt(bars[j+1].style.height)) {
await sleep(delay);
swapElements(bars[j], bars[j+1]);
}
bars[j].style.background = 'cyan';
bars[j+1].style.background = 'cyan' ;
}
bars[bars.length-i-1].style.background = 'green';
}
bars[0].style.background = 'green';
}
const bubbleSortBtn = document.querySelector('.bubbleSort');
bubbleSortBtn.addEventListener('click', async() => {
disableBtn();
disableSlideInputs();
await bubbleSort();
algoInfo.innerHTML = ` <p>Bubble Sort: </p>
<p> Space Complexity: O(1)</p>
<p> Time Complexity: O(n^2) </p>`
enableBtn();
enableSlideInputs();
})