排序算法的稳定性

A sorting method is stable if it preserves the relative order of equal keys in the array.

For example, suppose, in our internet commerce application, that we enter transactions into an array as they arrive, so they are in order of the time field in the array. Now suppose that the application requires that the transactions be separated out by location for further processing. One easy way to do so is to sort the array by location. If the sort is unstable, the transactions for each city may not necessarily be in order by time after the sort. Some of the sorting methods that we have considered in this chapter are stable (insertion sort and mergesort); many are not (selection sort, shellsort, quicksort, and heapsort).

posted @ 2013-05-01 23:33  ustcwizard  阅读(156)  评论(0)    收藏  举报