日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

STL中deque

發布時間:2023/11/27 生活经验 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 STL中deque 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

以下學習一下STL中另一種序列容器——deque。

deque表示double-ended queue,即雙向隊列,deque是通過作為動態數組的方式實現的,這樣可以在兩端插入元素。因此,deque可以在任何一個方向進行擴展。同時可以在中間插入元素。在開頭或結尾處插入元素非常的快,然而在中間插入元素將會比較耗時間,因此需要移動隊列中的元素。


定義deque容器的類名為deque。類deque的定義以及deque對象的各種操作函數的實現包含在頭文件<deque>中,因此,在程序中使用deque時,程序中必須包含如下語句:

?

#include <deque>


類deque中包含好幾個構造器,因此,當聲明一個deque對象時,可以通過各種方式進行初始化。如下表中提供的方式:

?


除了之前介紹的所有序列容器通用的操作意外,下表還描述了用來管理deque容器的元素的操作。各個語句展示了如何使用某一個特定的函數,其中假設deq是一個deque容器


下例展示了如何在程序中使用deque。

?

#include <iostream>
#include <deque>
#include <algorithm>
#include <iterator>using namespace std;int main()
{deque<int> intDeq;ostream_iterator<int> screen(cout, " ");intDeq.push_back(13);intDeq.push_back(75);intDeq.push_back(28);intDeq.push_back(35);cout << "intDeq: ";copy(intDeq.begin(), intDeq.end(), screen);cout << endl;intDeq.push_front(0);intDeq.push_back(100);cout << "After adding two more "<< "elements, one at the front " << endl<< "	and one at the back, intDeq: ";copy(intDeq.begin(), intDeq.end(), screen);cout << endl;intDeq.pop_front();intDeq.pop_front();cout << "After removing the first "<< "two elements, " << endl<< "	intDeq: ";copy(intDeq.begin(), intDeq.end(), screen);cout << endl;intDeq.pop_back();intDeq.pop_back();cout << "After removing the last "<< "two elements, " << endl<< "	intDeq: ";copy(intDeq.begin(), intDeq.end(), screen);cout << endl;deque<int>::iterator deqIt;deqIt = intDeq.begin();++deqIt;intDeq.insert(deqIt, 666);cout << "After inserting 666, "<< "intDeq: ";copy(intDeq.begin(), intDeq.end(), screen);cout << endl;intDeq.assign(2, 45);cout << "After assigning two "<< "copies of 45, intDeq: ";copy(intDeq.begin(), intDeq.end(), screen);cout << endl;intDeq.push_front(-10);intDeq.push_front(-999);cout << "After inserting two "<< "elements, one at the front " << endl<< "	and one at the back, intDeq: ";copy(intDeq.begin(), intDeq.end(), screen);cout << endl;return 0;
}

?

輸出為:

?



?

轉載于:https://www.cnblogs.com/riasky/p/3430770.html

總結

以上是生活随笔為你收集整理的STL中deque的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。