You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This Sorting Visualizer project is a JavaScript-based web application that allows users to visualize various sorting algorithms in action. Sorting algorithms are fundamental in computer science and understanding how they work can be both educational and fun. This project provides a visual representation of sorting algorithms, helping users grasp their inner workings through interactive animations.
moves.push({indices: [i-1,i],type: 'comp'});//we require type swap because we need to differentiate when we are comparing and when we are swapping to show respective move color.
43
+
if(array[i-1]>array[i]){
44
+
swapped=true;
45
+
moves.push({indices: [i-1,i],type: 'swap'});//we require type swap because we need to differentiate when we are comparing and when we are swapping to show respective move color.
46
+
[array[i-1],array[i]]=[array[i],array[i-1]];
47
+
}
48
+
}
49
+
}while(swapped);
50
+
returnmoves;
51
+
}
52
+
53
+
//render the bars dynamically in the index html file
54
+
functionshowBars(move){
55
+
container.innerHTML='';
56
+
for(leti=0;i<array.length;i++){
57
+
constbar=document.createElement('div');
58
+
bar.style.height=array[i]*10+'%';
59
+
bar.classList.add('bar');
60
+
bar.innerHTML=Math.floor(array[i]*10);
61
+
if(move&&move.indices.includes(i)){
62
+
bar.style.backgroundColor=move.type=='swap' ? 'red' : 'green';//red if swapping green if comparing
0 commit comments