Very quick response... you have the normal HUGE bug. When you split the 
array into a left and right chunk, you MUST stack the LARGER chunk, and 
sort the smaller one. That's why the stack space disappears.

And... be very careful about what happens when you can have duplicate 
values... what happens as the indices cross over in the middle? I think 
your code tends to fail safe... with a slight cost in overall speed.

Also... quicksort is NOT the fastest sort. Actually, bubblesort beats it 
for trivial cases. The choice of "median" value is not all that 
significant, but just choosing the one in the centre isn't that smart. 
Personally, I tend to eliminate the cases with less than three items as 
special cases. I then "bubblesort" the one in the middle with the ones 
at the two extrema. If there are now only three elements, we're done. 
Otherwise, /now/ we can use the one in the middle as a better stab at 
the median, and actually start the swapping one in from each end.

_______________________________________________
QL-Users Mailing List
http://www.q-v-d.demon.co.uk/smsqe.htm

Reply via email to