Re: Sorting




"Army1987" <please.ask@xxxxxx> wrote in message news:f0v338$32j$1@xxxxxxxxxxxxxxx

"Malcolm McLean" <regniztar@xxxxxxxxxxxxxx> ha scritto nel messaggio news:77OdnWahTNmt5a_bRVnyvwA@xxxxxxxxx
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.

What the hell? "Easiest"? I would have never thought of anything
similar, and when I was taught about it, I wandered why did anybody
bother to think and implement such a horrid algorithm. The answer
"it's a didactic toy" is the one which convices me best. It is even
less efficient than selection sort or insertion sort, which are
more human-comprehensible. (Which do you use to physically sort a deck of playing cards? I don't believe you use bubblesort.)

The algorithm isn't conceptually the simplest. But there is no memory management to speak of, so it is generally easier to implement.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

.



Relevant Pages

  • Re: Help me with references
    ... I can't think of any situation in which bubble sort is ... > best choice for a sorting algorithm in a real machine. ... Quicksort is optimized for large Ns. ... I picked Bubblesort because your original post implied something along ...
    (comp.lang.java.help)
  • Re: Okay to move an "object" will-nilly?
    ... I wrote a funky kind of algorithm for sorting an array (whether ... the objects in the array must be move safe. ... the array was already sorted so no swaps were performed by the sort. ...
    (comp.lang.c)
  • Re: Fastcode poll - Should Sort include worst case situations
    ... median algorithm, not O), there exists sequences that will beat ... quicksort and make it O. ... by many compiler vendors is "Engineering a Sort ... If it detects that a portion of an array is responding badly, ...
    (borland.public.delphi.language.basm)
  • Re: Hash table in C++? STL?
    ... The Oalgorithm is when you scan all ... > Assume array a and b both have N elements, ... > Will a binary search beat a hash lookup? ... Running time O) for the sort if using ...
    (comp.lang.cpp)
  • Re: Sort Two Dimensioanl Array
    ... Does Chris' Bubble Sort work - works in 2003 Autotext. ... Sort the given array into order. ... Optional SortAscending As Boolean = True) ... Dim BubbleSort As Long ...
    (microsoft.public.word.vba.general)

Loading