0
for(.........)
{

    for(.........)
     {
              swap
     }

}

Is there really a better way to sort a one dimensional array then to just use a simple bubble sort? Ive heard arguments against bubble sort before, but what do you guys think?

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by LevyDee
0

http://people.cs.ubc.ca/~harrison/Java/sorting-demo.html

Well it depends on what you're doing. 50 years of research and dozens (if not hundreds) of algorithms means there isn't a single "one size fits all".

A 10-slot game highscore table, which is already sorted (except for the entry you just added) doesn't need you to implement anything other than a crude bubble-sort (unless something like qsort is available as a library function).

But a few million records in random order, you'd be bone-head stupid to try using bubblesort on that. The O(n^2) would crucify you.

0

Depends on how large it is. It works just fine for small arrays -- say 1000 or less. Larger than 10,000 you might want to try something else if the sort takes too long.

-1

Well, sorting a few million random records you would want to use a vector or linked list right(without getting into the technicality of the context)?

Edited by LevyDee: n/a

Votes + Comments
OK, Levy. Responding to every post in the forums is not necessary when you have nothing worthwhile to add.
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.