CHAPTER7-8.cpp
上传用户:fjc899
上传日期:2007-07-03
资源大小:187k
文件大小:1k
- //文件名:CHAPTER7-8.cpp
- #include <deque>
- #if _MSC_VER > 1020 // if VC++ version is > 4.2
- using namespace std; // std c++ libs implemented in std
- #endif
- #include <iostream>
- int main( )
- { deque <int> c1;
- deque <int>::iterator c1_Iter;
- deque <int>::reverse_iterator c1_rIter;
- c1.push_back( 10 );
- c1.push_back( 20 );
- c1.push_back( 30 );
- c1_rIter = c1.rbegin( ); //指向c1的最后一个元素
- cout << "Last element in the deque is " << *c1_rIter << "." << endl;
- cout << "The deque contains the elements: ";
- for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
- cout << *c1_Iter << " "; //顺序显示deque的元素
- cout << "in that order.";
- cout << endl;
- cout << "The reversed deque is: ";
- for ( c1_rIter = c1.rbegin( ); c1_rIter != c1.rend( ); c1_rIter++ )
- cout << *c1_rIter << " ";//反序显示deque的元素
- cout << endl;
- c1_rIter = c1.rbegin( );
- *c1_rIter = 40; // This would have caused an error if a const_reverse iterator had been declared
- //as noted above
- cout << "Last element in deque is now " << *c1_rIter << "." << endl;
- return 0;
- }