BW> That's a good one, I didn't think it would work, but it does. Seems
If you think that bubble sort is a good sorting algorithm, I have to
object.
BW> go through the entire array, moving higher values to the left, setti
BW> test=0 if there was a sort performed, so the while loop gets perform
BW> again on the entire array. Thanks for the loop!
The number of times two elements are compared is proportional to the
square of the number of elements in the average case. Other algorithms
are much faster.
On the other hand, the trick with the test variable gives this
implementation a very good performance if the array is already
(almost) sorted (proportional to the number of elements). But that's
not very interesting usually.
Thomas
---
þ MM 1.0 #0113 þ Remember - you're unique, just like everybody else.
---------------
* Origin: McMeier & Son BBS (2:301/138)
|