Source of is_partitioned1a.cpp


  1: //is_partitioned1a.cpp

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

  9: int main()
 10: {
 11:     cout << "\nThis program illustrates the use of the STL "
 12:         "is_partitioned() algorithm from\n<algorithm> to test whether "
 13:         "a vector of integers is partitioned into odd and\neven integers.";
 14:     cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');

 16:     int a[] = {1, 3, 5, 7, 9, 2, 4, 6};
 17:     int b[] = {2, 4, 6, 1, 3, 5, 7, 9};
 18:     int c[] = {1, 3, 5, 7, 9, 11, 13, 15};
 19:     int d[] = {2, 4, 6, 8, 10, 12, 14, 16};
 20:     vector<int> va(a, a+8);
 21:     vector<int> vb(b, b+8);
 22:     vector<int> vc(c, c+8);
 23:     vector<int> vd(d, d+8);
 24:     cout << boolalpha;
 25:     cout << is_partitioned(va.begin(), va.end(),
 26:         [](int n) {return n%2==1;}) << endl;
 27:     cout << is_partitioned(vb.begin(), vb.end(),
 28:         [](int n) {return n%2==1;}) << endl;
 29:     cout << is_partitioned(vc.begin(), vc.end(),
 30:         [](int n) {return n%2==1;}) << endl;
 31:     cout << is_partitioned(vd.begin(), vd.end(),
 32:         [](int n) {return n%2==1;}) << endl;
 33:     cout << "Press Enter to continue ... "; cin.ignore(80, '\n');
 34: }