#include #include #include #include //for sort #include //for greater #include "date.h" //Return true if a should be closer to the start of the container than b. inline bool greater_int_function(int a, int b) {return a > b;} class greater_int { public: //Return true if a should be closer to the start of the container than b. bool operator()(int a, int b) const {return a > b;} }; class greater_date { public: //Return true if a should be closer to the start of the container than b. bool operator()(const date& a, const date& b) const {return a > b;} }; int main() { int a[] = {1, 3, 0, 2, 4}; const size_t n = sizeof a / sizeof a[0]; sort(a, a + n); //sort(&a[0], &a[n]); for (int i = 0; i < n; ++i) { cout << a[i] << "\n"; } cout << "\n"; date d[] = { date(date::october, 29, 1929), date(date::july, 20, 1969), date(date::july, 4, 1776), date(date::december, 7, 1941) }; const size_t n1 = sizeof d / sizeof d[0]; vector v(d, d + n1); sort(v.begin(), v.end()); for (vector::const_iterator it = v.begin(); it != v.end(); ++it) { cout << *it << "\n"; } cout << "\n"; sort(a, a + n, greater_int_function); for (int i = 0; i < n; ++i) { cout << a[i] << "\n"; } cout << "\n"; sort(a, a + n, greater_int()); for (int i = 0; i < n; ++i) { cout << a[i] << "\n"; } cout << "\n"; sort(a, a + n, greater()); for (int i = 0; i < n; ++i) { cout << a[i] << "\n"; } cout << "\n"; sort(v.begin(), v.end(), greater_date()); for (vector::const_iterator it = v.begin(); it != v.end(); ++it) { cout << *it << "\n"; } cout << "\n"; return EXIT_SUCCESS; }