Source of is_sorted2a.cpp


  1: //is_sorted2a.cpp

  3: #include <iostream>
  4: #include <iomanip>
  5: #include <vector>
  6: #include <algorithm>
  7: #include <functional>
  8: using namespace std;

 10: int main()
 11: {
 12:     cout << "\nThis program illustrates the use of the STL "
 13:         "is_sorted() algorithm from\n<algorithm> and the "
 14:         "greater<int>() functor from <functional> to test "
 15:         "\nwhether a vector of integers is sorted in "
 16:         "descending order.";
 17:     cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');

 19:     int a[] = {5, 4, 3, 2, 1};
 20:     int b[] = {5, 4, 3, 1, 2};
 21:     vector<int> va(a, a+5);
 22:     vector<int> vb(b, b+5);
 23:     cout << boolalpha;
 24:     cout << is_sorted(va.begin(), va.end(), greater<int>()) << endl;
 25:     cout << is_sorted(vb.begin(), vb.end(), greater<int>()) << endl;
 26:     cout << "Press Enter to continue ... "; cin.ignore(80, '\n');
 27: }