Bubble Sort Visualizer

Bubble Sort

Bubble Sort is the OG "simple" algorithm. it works by repeatedly swapping adjacent elements if they're in the wrong order. it "bubbles" the largest element to the end in every pass.

void bubbleSort(int arr[], int n) {
    for (int i = 0; i < n - 1; i++)
        for (int j = 0; j < n - i - 1; j++)
            if (arr[j] > arr[j + 1])
                swap(arr[j], arr[j + 1]);
}


        

Practice

Level Up