- First, we will generate a random array using Math.random() function.
- Different colors are used to indicate which elements are being compared, sorted, and unsorted.
- Since the algorithm performs the operation very fast, the setTimeout() function has been used to slow down the process.
- New array can be generated by pressing the “Ctrl+R” key.
- The sorting is performed using BubbleSort() function using swap() function
Below is the program to visualize the Bubble Sort algorithm.
style.css: The following is the content for “style.css” used in the above file.
script.js: The following is the content for “script.js” file used in the above HTML code.