TIP: Click on subject to list as thread! ANSI
echo: locuser
to: Bob Lawrence
from: Roy McNeill
date: 1997-04-30 23:26:06
subject: File Sort

Hi Bob

 BL> Hi all,
 BL>         I wrote a macro in WordBasic which needed to load a directory
 BL> of sorted files into a dialog array, and I've always thought there had
 BL> to be a neat way to sort the files as they go into the array, rather
 BL> than do it twice. This is it.


 BL>   All I do is load the first filename into the aray (to avoid a nul),
 BL> then check the next filename against the array from the top-down,
 BL> moving them all up one until I find one that isn't larger. Then I
 BL> write the new filename one-up... unless it's the 0-th in the array in
 BL> which case I write it there. That way, if the files are already
 BL> sorted, I don't have to do anything but write the names in.

Neat. This is the insertion sort. One nifty feature of it is that
it can run quicker on a "nearly sorted" array.

 BL>   It's pretty quick...

True. It's only worth pursuing more complex sorting routines if
you're sorting huge numbers of things.

Cheers

--- PPoint 1.88
* Origin: Silicon Heaven (3:712/610.16)
SEEN-BY: 711/934 712/610
@PATH: 712/610 711/934

SOURCE: echomail via fidonet.ozzmosis.com

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™.