CodeMonkey wrote:
The code that ResidentBiscuit originally posted looks like a basic bubble sort to me. |
Yes it looks, but think it over, what it does. And then you will know.
I see, the smallest is placed at the first place, but the second smallest is placed at increasing positions. This means: nothing bubbles.
The first place is used simply as my variable "minimum", and the performance is more bad, because of always exchanging elements.
But: if you decrease the inner j, as I did, this could be a more better bubble sort than mine - I don't know yet, you should think it over - yes it would, it needs less swaps - this means less write accesses to memory and so a better performance - and the performance would be still more better, if you don't place the smalles element into the first place, but hold it in a register, and store it to the first place after the inner loop. And don't forget swapped.
If you could implement the outer loop, and could follow my thoughts, you can implement the inner loop and then
it's finished.
Oh I thought it over again, your bubble sort wouldn't be a bubble sort. You begin with exchanging the element at the highest position - if its smaller - with the element at the lowest position. This means, the smaller bubble down, but the bigger don't bubble up. Instead you replace the highest position with the lowest position - or similar - now I got it - you only would do a bubble sort for elements smaller than the first one you took - nothing happens to bigger ones - exept that one at the lowest position - oh that's the same as I already had said before.
You should take my bubble sort.
Do you understand now about implementation? It has not much to do with C or assembly - it's imagination. C or assembly is just the notation, how you write it. |
And do you know, how I learned this? By coding in assembly. Your RAM is your empty pieces of paper. And you can draw all on it, what you can imagine and in assembly without any syntactical restrictions of higher programming languages.
Sounds like Selection sort to me. |
Sorry, it was a long time ago, I had known the difference between a list and a selection sort. But I forgot. Maybe this is called selection sort.