DN>>> for (i = n - 1; i > 0; --i)
DN>>> for (j = 1; j <= i; ++j)
DN>>> if (array[j-1] > array[j]) { /* swap j-1 with j */ }
TT>> for (i1=0; i1> for (i2=i1; i2> if (elem[i1]>elem[i2]) { /* swap i2 with i1 */ }
GW> It's not a "bubble sort", [...]
Yes it is. I've elided the exchange code in both Tom's and David's code,
which should make it clearer that they are, in essence, the same thing,
merely processing the array in different directions. Tom's code is, in fact,
closer to the "classic" Bubble Sort that most people think of, since it
processes the array in the same direction as the final intended ordering.
Given that David has previously bemoaned the fact that all that anyone seems
to do in this echo is post Bubble Sort, I find it ironic and amusing that
neither you nor he can actually recognise it when presented with it. Perhaps
echo participants should be encouraged to post Bubble Sort *more often*, so
that you two can sharpen your recognition skills. (-:
¯ JdeBP ®
--- FleetStreet 1.19 NR
---------------
* Origin: JdeBP's point, using Squish (2:440/4.3)
|