Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!ucbvax!ulysses!ulysses.att.com!cjc From: cjc@ulysses.att.com (Chris Calabrese) Newsgroups: comp.lang.c Subject: Re: Sorting anything with qsort Message-ID: <14539@ulysses.att.com> Date: 25 Mar 91 16:32:36 GMT References: <8164@crash.cts.com> Sender: netnews@ulysses.att.com Organization: AT&T Bell Laboratories, Murray Hill Lines: 32 jludwig@pro-grouch.cts.com (Jerry Ludwig) writes: > > Recently, (friday, that is) I finished my first program that sort using >qsort. The problem with sorting ANYTHING with qsort is that it wants an >array. I had to sort records in a file. Another problem is that qsort >takes only an unsigned int as the number of arguements and the files I had >to sort could easily be multiple megs (a record was only 14 bytes). Now >all of this was solved easily using multiple qsorts on records read into >a huge array and then merging the qsorts into the final file. But qsort is >not an end all for sorting ANYTHING by any stretch of the imagination. >qsort is a big help on almost all fixed size elements. Yes, qsort() is a sort algorithm, not a way of life. If you want to sort large ammounts of data, the method mentioned above is much better - sort chunks and merge them. Aside from the obvious fact that qsort() can only handle a relatively small number of objects to be sorted, you'll get much better performance out of the merge stratagy when you have more than about 2 mega bytes of data (a number arrived at by closely guarded secret methods :-) using lots of data generated locally). This number is independant of physical memory size (assuming you have sizably more than 2mb), but dependands on relative disk/memory/cpu speeds. Using this method, you can sort very large data sets in a predictable and reasonable time. Name: Christopher J. Calabrese Brain loaned to: AT&T Bell Laboratories, Murray Hill, NJ att!ulysses!cjc cjc@ulysses.att.com Obligatory Quote: ``pher - gr. vb. to schlep. phospher - to schlep light.philosopher - to schlep thoughts.''