in reply to Re^4: In-place sort with order assignment
in thread In-place sort with order assignment
I am confident that, in addition to my hash, I can have two additional arrays with 1000 items each. On the first pass through the hash using each, you check to see if the current key in the hash is lt than the first element in the array. If yes, you unshift, if not you check the next item until you find the proper location and use splice. If you reach the end of the array and it is less than 1000, you push. At the end, you check if you have 1001 items and you pop. At the end of the first pass, you now know the first 1000 items. You begin your second pass. This time, when you encounter an item in your first array, you assign its appropriate value while simultaneously populating the 2nd array (using the last element of the first).
Now of course this is silly - there are much better data structures than an array but I hope you get the idea.
Cheers - L~R
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^6: In-place sort with order assignment
by BrowserUk (Patriarch) on Sep 19, 2010 at 15:37 UTC | |
by Limbic~Region (Chancellor) on Sep 19, 2010 at 16:52 UTC | |
by BrowserUk (Patriarch) on Sep 19, 2010 at 19:19 UTC | |
by Limbic~Region (Chancellor) on Sep 20, 2010 at 01:16 UTC | |
by BrowserUk (Patriarch) on Sep 20, 2010 at 07:40 UTC | |
| |
by Limbic~Region (Chancellor) on Sep 19, 2010 at 23:17 UTC | |
by Limbic~Region (Chancellor) on Sep 23, 2010 at 18:48 UTC |