With the approach I outlined, you won't need any additional data structures beyond what you already have. You will be modifying your current list of items as you output bins though, as I already described.
If you want to keep your unbinned array, make a copy before binning or start with the last item considered as candidate instead of the first position in the array instead.
I highly recommend working through any algorithm on paper until you feel confident with how it works and what kind of data it accesses.
|