On Dec 3, 15:09, Christopher Smith wrote:
> "Let A[1:n] be an array of n numbers.
>
> ...
>
> Make repeated sweeps over the array A[1:n] from left to right. Upon
> detecting any adjacent pair of numbers A[i] and A[i+1] not in proper
order,
> exchange them A[i] <-> A[i + 1]. When a pass is completed with no
exchanges
> having been made, the process terminates.
Hmm, well, that's (almost) the worst example I've ever seen :-)
You're supposed to stop one position shorter each time, because by the end
of the sweep, the largest (or smallest, depending on which way you do the
comparison-and-swap) number has fallen to the bottom (end) of the array.
It makes a big difference to the time it takes.
--
Pete Peter Turnbull
Network Manager
University of York
Received on Mon Dec 03 2001 - 19:27:16 GMT