Bubble sort and rand()

M

Michael Campbell

I don't know if bubble sort using a random number for comparisons
is
always a good idea. Bubble sort runs over the array and compares two
subsequent values and swaps them if they are out of order.
It keeps doing that until there are no more swaps during a run.

No, that's an optimization to end early if there *ARE* no swaps. The
sort still just runs through the list a maximum n (or n-1) times. (Or
at least there's no reason NOT to.)

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top