Re: Sorting
- From: "Malcolm McLean" <regniztar@xxxxxxxxxxxxxx>
- Date: Sat, 28 Apr 2007 12:23:24 +0100
"Army1987" <please.ask@xxxxxx> wrote in message news:f0v338$32j$1@xxxxxxxxxxxxxxx
The algorithm isn't conceptually the simplest. But there is no memory management to speak of, so it is generally easier to implement.
"Malcolm McLean" <regniztar@xxxxxxxxxxxxxx> ha scritto nel messaggio news:77OdnWahTNmt5a_bRVnyvwA@xxxxxxxxxThere 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.)
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm
.
- Follow-Ups:
- Re: Sorting
- From: Army1987
- Re: Sorting
- References:
- Sorting
- From: Umesh
- Re: Sorting
- From: Malcolm McLean
- Re: Sorting
- From: Army1987
- Sorting
- Prev by Date: Re: C a Dead Language
- Next by Date: 2-d array using pointers
- Previous by thread: Re: Sorting
- Next by thread: Re: Sorting
- Index(es):
Relevant Pages
|
Loading