[C++] c++ 使用STL双端队列类 →→→→→进入此内容的聊天室

来自 , 2019-04-28, 写在 C++, 查看 120 次.
URL http://www.code666.cn/view/59bcda7c
  1. // 使用STL双端队列类
  2. #include <deque>
  3. #include <iostream>
  4. #include <algorithm>
  5.  
  6. int main() {
  7.         using namespace std;
  8.  
  9.         // Define a deque of integers
  10.         deque<int> dqIntegers;
  11.  
  12.         // Insert integers at the bottom of the array
  13.         dqIntegers.push_back(3);
  14.         dqIntegers.push_back(4);
  15.         dqIntegers.push_back(5);
  16.  
  17.         // Insert integers at the top of the array
  18.         dqIntegers.push_front(2);
  19.         dqIntegers.push_front(1);
  20.         dqIntegers.push_front(0);
  21.  
  22.         cout << "The contents of the deque after inserting elements ";
  23.         cout << "at the top and bottom are:" << endl;
  24.  
  25.         // Display contents on the screen
  26.         for (size_t nCount = 0; nCount < dqIntegers.size(); ++nCount) {
  27.                 cout << "Element [" << nCount << "] = ";
  28.                 cout << dqIntegers[nCount] << endl;
  29.         }
  30.  
  31.         cout << endl;
  32.  
  33.         // Erase an element at the top
  34.         dqIntegers.pop_front();
  35.  
  36.         // Erase an element at the bottom
  37.         dqIntegers.pop_back();
  38.  
  39.         cout << "The contents of the deque after erasing an element ";
  40.         cout << "from the top and bottom are:" << endl;
  41.  
  42.         // Display contents again: this time using iterators
  43.         deque<int>::iterator iElementLocator;
  44.         for (iElementLocator = dqIntegers.begin()
  45.         ; iElementLocator != dqIntegers.end(); ++iElementLocator) {
  46.                 size_t nOffset = distance(dqIntegers.begin(), iElementLocator);
  47.                 cout << "Element [" << nOffset << "] = " << *iElementLocator << endl;
  48.         }
  49.  
  50.         return 0;
  51. }
  52.  

回复 "c++ 使用STL双端队列类"

这儿你可以回复上面这条便签

captcha