TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: ALL
from: DAVID NOON
date: 1998-04-22 21:40:00
subject: Quicksort, Final Version

In a message dated 04-21-98, David Noon said to All about Quicksort, Final
Version
Hi All,
[snip]
In the ascending routine:
DN>         // If the subfile is short use Insertion sort
DN>         if (r > l)
DN>         {
DN>            for (i = l + 1; i <= r; ++i)
DN>            {
DN>               Hold_it_here = array[i];
DN>               for (j = i; j > l && array[j-1] > Hold_it_here; --j)
DN>                  array[j] = array[j-1];
DN>               array[j] = Hold_it_here;
DN>            }
DN>         }
[snip]
In the descending routine:
DN>         // If the subfile is short use Insertion sort
DN>         if (r > l)
DN>         {
DN>            for (i = l + 1; i <= r; ++i)
DN>            {
DN>               Hold_it_here = array[i];
DN>               for (j = i; j > l && array[j-1] < Hold_it_here; --j)
DN>                  array[j] = array[j-1];
DN>               array[j] = Hold_it_here;
DN>            }
DN>         }
In the above, the if (r > l) comparisons are redundant. A good optimizer
will filter them out, but it would have been better had I deleted them as
part of removing the "safety mechanisms" prior to releasing the code.
[Sorry!]
So, just delete the surrounding if statements and their braces from the for
loops. It might save you a nanosecond here and there.
Regards
Dave

___
 * MR/2 2.25 #353 * One man's Windows are another man's walls.
--- Maximus/2 3.01
---------------
* Origin: DoNoR/2,Woking UK (44-1483-717905) (2:440/4)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.