Bubble Sort Visualization
How Bubble Sort Works
Bubble Sort is a simple sorting algorithm that repeatedly steps through the list, compares adjacent elements and swaps them if they are in the wrong order. The pass through the list is repeated until the list is sorted. The algorithm gets its name from the way smaller elements 'bubble' to the top of the list with each iteration.
function bubbleSort(array):
for i from 0 to array.length - 1:
for j from 0 to array.length - i - 1:
if array[j] > array[j+1]:
swap array[j] and array[j+1]
visualize(array, j, j+1)
return array