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?

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.

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.

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)?

commented: OK, Levy. Responding to every post in the forums is not necessary when you have nothing worthwhile to add. -2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.