Optimized Quicksort (3rd ed., p 142)
Should the comparison be changed from <= to <, since there's no need to swap an element with itself, unless
the swap isn't important (i.e., it doesn't do any harm) at that point and the need is just to adjust both i and j variables?
// If the values are in the wrong order, swap them.
if( i <= j ){
Compared to
// ...
if( i < j ) {
Thanks,
Last edited by mjr; March 12th, 2015 at 02:57 PM..
|