[fpc-devel] TStringList.CustomSort

Mattias Gaertner nc-gaertnma at netcologne.de
Tue Nov 7 10:35:39 CET 2006


On Tue, 07 Nov 2006 10:17:24 +0100
Micha Nelissen <micha at neli.hopto.org> wrote:

> Chris Cheney wrote:
> > Stating the obvious: but the programmer might wish to sort by the
> > objects or by some combination of the strings and the objects (or
> > even by entries in an external array, unrelated to the StringList)
> > - the indexes are therefore needed in the general case.
> 
> Oh right, sorting by object contents. Seems strange to me, but
> perhaps useful, indeed.
> 
> > Of course, the efficient way to build a sorted list is to set
> > Sorted to False and to sort the list after all the items have been
> > added.
> 
> It doesn't matter in O-time: both are O(n log n). Nevertheless, you 
> probably will save some function call overhead.

Insertion Sort is O(n^2).


Mattias



More information about the fpc-devel mailing list