Subject: Re: Aw: Re: [stella] Sorting Algorithms. From: Thomas Jentzsch <tjentzsch@xxxxxx> Date: Mon, 25 Mar 2002 17:41:31 +0100 |
Manuel wrote: >Well, in this example the zero would be sorted to the beginning >in one iteration, but: >Having 1,2,3,4,5,6 and adding the 7 at the _beginning_, would >be worst case, or? And that can happen any time, I think. Why would you add something at the beginning, if you know that causes worst case? ;-) My (non standard!) pseudocode looks like this: (sorting n+1 elements) for i = 0 to n-1 for j = n-1 downto i if y[j+1] < y[j] then swap(j, j+1) So, I will always add at the end, no matter what value. >Hm... to always have stuff inserted at one side, you'd >have to shift all indexes together, once an object >disappears, right? Hm.... hm... might work. Yes, removing from the list should be done seperate. >Then the max number of (outerloop) iterations = number >of objects inserted, yes? Nearly. Add 1 to recognize, that the list is sorted. Have fun! Thomas ---------------------------------------------------------------------------------------------- Archives (includes files) at http://www.biglist.com/lists/stella/archives/ Unsub & more at http://www.biglist.com/lists/stella/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: Aw: Re: [stella] Sorting Algori, Julian Squires | Thread | Aw: Re: Aw: Re: [stella] Sorting Al, cybergoth |
Aw: Re: Aw: Re: Aw: Re: [stella] So, cybergoth | Date | Aw: Re: Aw: Re: Aw: Re: [stella] So, cybergoth |
Month |