Standard C++ Library Class Reference
Description
The stable_sort algorithm sorts the elements in the range [first, last). The first version of the
algorithm uses less than (<) as the comparison operator for the sort. The second version uses the
comparision function comp.
The stable_sort algorithm is considered stable because the relative order of the equal elements
is preserved.
Complexity
stable_sort does at most N(logN) **2, where N equals last -first, comparisons; if enough extra
memory is available, it is NlogN.
Example
//
// sort.cpp
//
 #include <vector>
 #include <algorithm>
 #include <functional>
 #include <iostream.h>
 struct associate
 {
 int num;
 char chr;
 associate(int n, char c) : num(n), chr(c){};
 associate() : num(0), chr('\0'){};
 };
 bool operator<(const associate &x, const associate &y)
 {
 return x.num < y.num;
 }
 ostream& operator<<(ostream &s, const associate &x)
 {
 return s << "<" << x.num << ";" << x.chr << ">";
 }
 int main ()
 {
 vector<associate>::iterator i, j, k;
 associate arr[20] = 
 {associate(-4, ' '), associate(16, ' '),
 associate(17, ' '), associate(-3, 's'),
 associate(14, ' '), associate(-6, ' '),










