Subj : Re: Sorting To : borland.public.cpp.borlandcpp From : Nokomis Date : Wed Dec 17 2003 07:38 pm Bob Gonder wrote: > Nokomis wrote: > > >Anyone know an algorithm for sorting large numbers of character strings? > > > >Something like a telephone direcctory - too big for a normal array. > > Data resides in a file? > Is this fixed-length records or variable? > You know Bubble Sort, right? > > Use Bubble Sort algorythm for the outside block, and the fastest sort > you care to use for the inner block. > > Array[2000] > RecordPointer A=0,B; > > while( A < FileRecords-1000 ) > { > read 1000 records from A into Array[0] > B = A+1000 > if( B >= FileRecords ) > fastsort 2000 records /* small file */ > while( B < FileRecords ) > { read 1000 records from B into Array[1000] > fastsort 2000 records > write 1000 records to B from Array[1000] > B+=1000 > } > write 1000 records to A from Array[0] > A += 1000 > } > Adjust "1000" to suit your memory/speed requirements. > Since this is an "in-place" sort, it would be safer to copy the file, > sort the copy, then rename upon completion. That way a power outage or > other mishap won't leave you with scrambled data. Bob, Yes, that's neat. I was thinking along those lines slightly differently. Running through the file, finding the smallest, writing that to file B and deleyeing it form file A.. The repeat the search for the smallest etc etc. Comes to much the same thing! Yes, of course make a copy! Thanks. G .