From: Thomas Demmer Newsgroups: comp.os.msdos.djgpp Subject: Re: Sorting Algorythums Date: Mon, 23 Feb 1998 08:43:12 +0100 Organization: Lehrstuhl fuer Stroemungsmechanik Lines: 37 Message-ID: <34F12890.57F35CC9@LSTM.Ruhr-UNI-Bochum.De> References: <34F113BA DOT 203AD4E9 AT earthlink DOT net> NNTP-Posting-Host: bvb.lstm.ruhr-uni-bochum.de Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk STEVEN S. FALLS wrote: > > What is the best sorting algorythm and what is it. I mean, how would > one program the algrothym? There is no thing as _the_best_ sorting algorithm. It depends on the number of items you want to sort, how the data is pre-sorted, if there are memory constraints etc. One of the best, on average, is quicksort, which takes O(n log(n)) operations (from the back of my head, no gurantees). It can be a bit quirky when the collection is nearly sorted, or sorted in reverse order. See the implementation in libc for an implementation that is modified to avoid some of the pitfalls. A simpler one is bubblesort, where you plough through the list, comparing an element with the next one. If they are out of order, the get swapped. This is repeated until no more swappings occur in one run. IIRC, Sedgwick's "Alogrithms in C" has a few examples. -- Ciao Tom ************************************************************* * Thomas Demmer * * Lehrstuhl fuer Stroemungsmechanik * * Ruhr-Uni-Bochum * * Universitaetsstr. 150 * * D-44780 Bochum * * Tel: +49 234 700 6434 * * Fax: +49 234 709 4162 * * http://www.lstm.ruhr-uni-bochum.de/~demmer * *************************************************************