What is stable sorting?
Location: http://www.jguru.com/faq/view.jsp?EID=225366 Created: Oct 9, 2000 Modified: 2005-08-15 12:58:19.757 Author: Avi Kak (http://www.jguru.com/guru/viewbio.jsp?EID=26410) The collections framework specification requires that the sorting algorithms be stable. Stated succinctly, a sorting algorithm is stable if it does not reorder equal elements. But what does that really mean? The goal of this posting is to illustrate this concept. Stability in sorting becomes an issue for class-type objects with two or more data members. We’d obviously need to choose a data member whose values will be used to order the objects for sorting. Let’s say we have multiple objects in a list whose values for the data member chosen for comparison are the same, but whose values for the other data members are different. A stable sorting algorithm will leave the original order of such objects untouched. Stability in sorting, or lack thereof, is best illustrated by comparing the sorted order obtained through t