0.3.8 Bubble Sort
The Bubble Sort has no redeeming characteristics. It is always very
slow, no matter what data it is sorting. This algorithm is included
here for the sake of completeness, not because of any merit.
The C code for a Bubble sort follows:
void bubblesort (int *array, int size) {
int i, j;
for (i = 0; i < size; i++)
for (j = size - 1; j > i; j--)
if (array[j] < array[j-1]) swapi(&array[j], &array[j-1]);
}
A Bubble Sort always runs in n2 time and is a very poor choice for
a sorting algorithm in any circumstance.
|