What the heck is a bubble sort?

Started by
21 comments, last by Tsu 23 years ago
A little "bubble" variation that does the same... This way is easier to remember for me

for(int i = 0; i < n - 1; i++)
{
for(int j = i; j < n ; j++)
{
if(array > array[j])
// assume a function that switches two variables...
swap(array, array[j]);<br>}<br>} <br><br><br>EDU<br> </i>
Advertisement
The bubble sort is the easiest to implement and it is also the smallest to code. In college we had a program to write in (VMS) asm - the objective was to make it as small as possible and input/sort/output 10 integers. Everyone used a bubble sort because it takes ~6lines of asm.

The insertion sort is faster than a quick or merge sort on nearly sorted data - much faster if you know the list is already sorted.

And the quick sort ain''t so quick when it''s done with recursive functions - for the same reason recursive FFTs are hideously slow.

Magmai Kai Holmlor
- The disgruntled & disillusioned
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
The fast quick sort appears to quicksort the data until it''s in an almost-sorted state, then switches to an insertion sort. Seems quite effecient to me.

If you really want to get a good idea of how long it all takes, use a profiler.

This topic is closed to new replies.

Advertisement