Re: Sorting



Malcolm McLean wrote:

"Umesh" <fraternitydisposal@xxxxxxxxx> wrote in message news:1177664304.581212.237870@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I don't understand it. Help me by writing a program while i try myself
to sort an array of numbers. Thanks.

There are lots of ways of sorting.
The easiest, probably, is to go through the array. Compare the number you are on with the number above it. If they are in the wrong order, swap them. Then go back to the start of the array and do it again, until you make a clean sweep without swapping. Set a flag when you swap, and clear it each time you restart.
This algorithm is called bubblesort.

... a.k.a. "The Second-Worst Sorting Algorithm in the
Literature." Vastly inferior to the selection sort already
posted (once its errors are fixed).

--
Eric Sosman
esosman@xxxxxxxxxxxxxxxxxxx
.



Relevant Pages

  • Re: Need help sorting by specific fields in file.
    ... > I have a file that I need to sort and currently I am just ... You're sorting an array. ... grab the first 6 characters off of all of them, ... That's just a basic grab the first 6 numbers and compare approach. ...
    (perl.beginners)
  • Re: An inefficiency in Array.Sort
    ... use a temporary array, and Array.Sort is an in-place sort. ... they repeatedly compare ato a. ... former really makes no sense at all, especially presuming a QuickSort ... It is possible that the sort algorithm loses track of the original array ...
    (microsoft.public.dotnet.languages.vb)
  • Re: "Sorting" assignment
    ... And many others prefer to call partition exchange because "quicksort" ... bin B depending on whether it is greater than, ... If the array is already sorted, this means that you end up ... attempt to sort them. ...
    (comp.programming)
  • Re: Fortran templates
    ... into "having a method which sorts the client-side array". ... have to explicitly define the type of data to compare. ... code, whereas in my Fortran quicksort-with-callbacks, you must define ... However, if you want to sort *strings*, you will have to define ...
    (comp.lang.fortran)
  • Re: A Fast sorting algorithm for almost sorted data
    ... far my compressor has potential but is nowhere near ready. ... It does however make heavy use of sorting. ... which I am currently calling Run sort. ... entire selected run can be added to the sorted output array. ...
    (comp.compression)