sort(), stable_sort()
By default, sorts the elements in ascending order using the less-than operator. An optional third parameter allows us to pass in an alternative ordering operation. stable_sort() preserves the relative order of elements within the container. For example, imagine that we have sorted our words alphabetically and now wish to order them by word length. To do this, we pass in a function object LessThan that compares two strings by length. Were we to use sort(), we would not be guaranteed to preserve the alphabetical ordering.
#include <algorithm>
stable_sort( ia, ia+8 );
stable_sort( svec.begin(), svec.end(), greater<string>() );
|