1: //deque14.cpp 3: #include <iostream> 4: #include <string> 5: #include <deque> 6: using namespace std; 8: int main() 9: { 10: cout << "\nThis program illustrates the swap() member function " 11: "for deque objects."; 12: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 14: deque<int> d1(5, 5); 15: cout << "\nFor d1 we have:"; 16: cout << "\nSize = " << d1.size(); 17: cout << "\nContents: "; 18: for(deque<int>::size_type i=0; i<d1.size(); i++) 19: cout << d1.at(i) << " "; 20: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 22: deque<int> d2(10, 10); 23: cout << "\nFor d2 we have:"; 24: cout << "\nSize = " << d2.size(); 25: cout << "\nContents: "; 26: for(deque<int>::size_type i=0; i<d2.size(); i++) 27: cout << d2.at(i) << " "; 28: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 30: cout << "\nNow we swap d1 and d2 with d1.swap(d2) and redisplay."; 31: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 33: d1.swap(d2); 34: cout << "\nFor d1 we have:"; 35: cout << "\nSize = " << d1.size(); 36: cout << "\nContents: "; 37: for(deque<int>::size_type i=0; i<d1.size(); i++) 38: cout << d1.at(i) << " "; 39: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 40: cout << "\nFor d2 we have:"; 41: cout << "\nSize = " << d2.size(); 42: cout << "\nContents: "; 43: for(deque<int>::size_type i=0; i<d2.size(); i++) 44: cout << d2.at(i) << " "; 45: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 46: }