Skip to main content

Bubble Sort

Definition​

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

Practice​

function bubbleSort(arr)
n = length(arr)
swapped = true
while swapped is true
swapped = false
for i from 0 to n-2
if arr[i] > arr[i+1]
swap(arr[i], arr[i+1])
swapped = true