Source of inplace_merge1a.cpp


  1: //inplace_merge1a.cpp

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

  8: int main()
  9: {
 10:     cout << "\nThis program illustrates the use of the STL "
 11:         "inplace_merge() algorithm\n(default version) to merge two "
 12:         "sorted ranges of integer values in the\nsame vector into a "
 13:         "single sorted range of values within that same vector.";
 14:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');

 16:     int a[] = {1, 3 , 5, 7, 9, 11, 13, 2, 4, 6, 8, 10};
 17:     vector<int> v(a, a+12);

 19:     cout << "\nHere are the contents of v:\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:     inplace_merge(v.begin(), v.begin()+7, v.end());

 26:     cout << "\nNow we perform the \"in place merge\".";
 27:     cout << "\nHere are the revised contents of v:\n";
 28:     for (vector<int>::size_type i=0; i<v.size(); i++)
 29:         cout << v.at(i) << " ";
 30:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');
 31: }