1: //sort2b.cpp 3: #include <iostream> 4: #include <vector> 5: #include <algorithm> 6: #include <functional> 7: using namespace std; 9: int main() 10: { 11: cout << "\nThis program illustrates the use of the STL sort " 12: "algorithm, together with a\nbuilt-in STL function " 13: "object, to sort values in descending order."; 14: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 16: int a[] = {17, 12, 14, 19, 23, 15, 61, 20, 81, 11}; 17: vector<int> v(a, a+10); 19: cout << "\nHere are the original contents of a vector:\n"; 20: for (vector<int>::size_type i=0; i<v.size(); i++) 21: cout << v.at(i) << " ";; 22: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 24: sort(v.begin(), v.end(), greater<int>()); 26: cout << "\nAnd here they are sorted in descending order:\n"; 27: for (vector<int>::size_type i=0; i<v.size(); i++) 28: cout << v.at(i) << " "; 29: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 30: }