#include <iostream>
#include <list>
using namespace std;
int main()
{
list<int> listObject1, listObject2;
int i;
for(i = 10; i >= 0; i -= 2)
listObject1.push_back(i);
for(i = 11; i >= 1; i -= 2)
listObject2.push_back(i);
cout << "Original contents of listObject1:\n";
list<int>::iterator p = listObject1.begin();
while(p != listObject1.end())
cout << *p++ << " ";
cout << "\n\n";
cout << "Original contents of listObject2:\n";
p = listObject2.begin();
while(p != listObject2.end())
cout << *p++ << " ";
cout << "\n\n";
// merge using greater than, not less than
listObject1.merge(listObject2, greater<int>());
cout << "Merged contents of listObject1:\n";
p = listObject1.begin();
while(p != listObject1.end())
cout << *p++ << " ";
cout << "\n\n";
return 0;
}
|