From: "Philippe Ranger"
Subject: Re: Need sort function (algoritm)
Date: 19 May 1999 00:00:00 GMT
Message-ID: <7hv3n6$et620@forums.borland.com>
References: <7huj00$ef718@forums.borland.com>
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
Organization: PhilippeRanger@RemoveThis.compuserve.com
Reply-To: "Philippe Ranger"
Newsgroups: borland.public.delphi.objectpascal
<>
Delphi uses QuickSort, which is fairly optimized already. If you're only
storing strings, no objects, you might store them to a Tlist, and call
Tlist.sort with a compare function like this --
Function lengthCompare(p1, p2: pointer): integer;
Begin
result := length(string(p1)) - length(string(p2));
End;
After sorting, you could put your strings in a TstringList if you need that
for further operations.
Using a TstringList directly, TstringList.sort does not use a Compare
function, but it is virtual. If you have anything but the standard edition,
you have the source in Classes.pas. You could define your own TstringList
descendant, override Sort and create it by copying the code from
TstringList.sort. This calls QuickSort (private to Classes.pas), so you'd
copy the code for that too, and modify as above to sort on string length.
PhR