CHAPTER7-17.cpp
上传用户:fjc899
上传日期:2007-07-03
资源大小:187k
文件大小:1k
- //文件名:CHAPTER7-17.cpp
- #include <iostream>
- #include <deque>
- #if _MSC_VER > 1020 // if VC++ version is > 4.2
- using namespace std; // std c++ libs implemented in std
- #endif
- typedef deque<char > CHARDEQUE;
- void print_contents (CHARDEQUE deque);
- int main()
- { CHARDEQUE a(3,'A');
- CHARDEQUE b(2,'B');
- print_contents (a);
- print_contents (b);
- a.insert(a.begin(),'X'); // 在deque的头部插入一元素,值为'X'
- print_contents (a);
- a.insert(a.end(),'Y'); // 在deque的尾部插入一元素,值为'Y'
- print_contents (a);
- //inset 3 'Z's to one item before the end of a
- a.insert(a.end()-1,3,'Z'); // 在deque的尾部前一元素处插入3个元素,值为'Z'
- print_contents (a);
- a.insert(a.end(),b.begin(),b.end()); // 把b的所有值插入到a变量的尾部
- print_contents (a);
- return 0;
- }
- //deque的显示函数
- void print_contents (CHARDEQUE deque)
- { CHARDEQUE::iterator pdeque;
- cout <<"The output is: ";
- for(pdeque = deque.begin(); pdeque != deque.end(); pdeque++)
- { cout << *pdeque <<" " ; }
- cout<<endl;
- }