[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Bubble sort and rand

Michael Campbell

9/17/2003 5:19:00 PM

> 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...