Subj : Re: Sorting To : borland.public.cpp.borlandcpp From : nobody@xmission.com (Scott) Date : Thu Dec 18 2003 04:30 am On Wed, 17 Dec 2003 16:02:09 +0000, Nokomis wrote: >Anyone know an algorithm for sorting large numbers of character strings? > >Something like a telephone direcctory - too big for a normal array. >(5.01) There are many possible solutions to this problem. Some of them will be extremely slow. As a general approach, I'd suggest using an iterative sort-and-merge procedure. I once wrote a general-purpose program to sort arbitrarily large text files (e.g. variable-length records) using a sort/merge technique. The basic idea is to load data into memory until memory is full (or some other limit is reached), then use a fast algorithm to sort what's in memory before dumping it to a temporary file (each sorting run generates a new temp file). Repeat until the source data is exhausted. Then it's just a matter of running a merge process on the temporary files. I used an N-way merge based on the idea that it would avoid a lot of unneccesary I/O. N-way merging is just an extension of the basic merge technique that Ed Mulroy described, merging from many files instead of just two. The number of input files may be limited by your OS, which is why it's an iterative process. If you have more temp files than available file handles, you generate another temp file and re-do the merge process. Eventually you'll have fewer temp files than available handles, at which point you can generate your final output. -Scott -- Send replies to sierra kilo bravo at the obvious domain. .