Don't feel bad about not getting it at first, after all, a sorting method that does no > or < comparisons blew my mind at first (that was your code by the way
).
I'll give a shot at explaining.
Let's look at the problem like we are sorting different colored plates. (Hey! I do remember something from school
).
Pass 1:
Go over each pixel in the image (the pile of dishes).
Look at the hue of each plate (img.pixels[i]).
Put a sticky note next to each plate (at indexlist[i]) that tells which hue pile the plate should go to.
Count the number of sticky notes of the same color. To be efficient, we count them as we place the notes (counts[indexlist[i]]++).
Pass 2:
Make sure we have enough space in each hue pile for all of the plates.
(Allocate arrays)
Pass 3:
Stack the plates on their matching pile, keeping track of how many plates of each hue we have left (counts[indexlist[i]]--).
Pass 4:
Pick up each smaller stack and put them, in order, into the dish rack (out.pixels).
Forgive me if that was a little 'too' basic. It is similar to how a Stack was explained to me during one of my classes.
Edit: Just a side note, since I can't modify my other entry, will put here. I was mistaken before, this is actually a
http://en.wikipedia.org/wiki/Counting_sort. Similar to Radix I think.