Bubble Sort is a simple sorting algorithm that repeatedly swaps adjacent elements if they are in the wrong order.
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]);
}
Bubble sort is mainly used for educational purposes and small datasets due to its simplicity.
Take quizzes related to this topic and see where you stand!
Start Quiz Now