运动与环保齐名 思铂睿混动对比迈锐宝XL混动
Current License: CC BY-SA 2.5
6 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Mar 27, 2021 at 0:19 | comment | added | Bob Murphy | @augenss If two records both have key "foo", then before doing the sort, change them to something like "foo_00001" and "foo_00002". That will preserve the two keys' original order when you do the sort. Then when you're done with the sort, change both keys back to "foo". | |
Mar 26, 2021 at 20:49 | comment | added | augenss | In the last sentence, I don't understand what you mean with "last-place key for each record" - could you please explain? Very good informative comment overall :) | |
Feb 10, 2013 at 1:43 | comment | added | greggo | Best overall answer IMHO. the multi-key technique mentioned in others is interesting but overrated; it's simple to apply, but tends to be far slower than obvious alternatives (just use one sort with a multi-key compare; or sort by the first key then identify and sort any sublists with duplicates). The fact that stable sort produces a predictable result can be important in some apps. In particular if you have two input lists A,B which are identical except list B has an extra entry, the outputs for a stable sort will be identical except that B has that same extra entry. And +1 for last pgph. | |
Oct 5, 2009 at 4:40 | comment | added | Bob Murphy | Yes, and memory usage on Merge Sort is O(N), while on Quicksort it's O(log N). The reason I mentioned Quicksort is that qsort() is a C standard library routine, so it's reaily available. | |
Oct 5, 2009 at 2:14 | comment | added | Jonathan Leffler | Stable algorithms like Merge Sort have the same O(NlogN) complexity as Quicksort; the constant multiplier on the effort is bigger, though. | |
Oct 5, 2009 at 1:47 | history | answered | Bob Murphy | CC BY-SA 2.5 |