中国航天专家遭美拒签,河南科技市场,猫粮团购
deque即数组形式的双端队列。
#include<iostream> #include<deque> #include<algorithm> using namespace std; int main() { //构造 deque<int> d = { 2,6,8 }; //遍历 for (deque<int>::iterator it = d.begin(); it < d.end(); it++) cout << *it; cout << endl; //输出:268 //入队 //从队尾入队 d.push_back(9); //从队首入队 d.push_front(3); for (deque<int>::iterator it = d.begin(); it < d.end(); it++) cout << *it; cout << endl; //输出:32689 //出队 //从队首出队,无返回值 d.pop_front(); //从队尾出队,无返回值 d.pop_back(); for (deque<int>::iterator it = d.begin(); it < d.end(); it++) cout << *it; cout << endl; //输出:268 //获取元素,与vector相同 cout << d[0] << endl; //不检查下标是否越界,但速度较快。输出:2 cout << d.at(2) << endl; //检查下标是否越界。输出:8 //排序 sort(d.begin(), d.end(),greater<int>()); //从大到小排序 for (deque<int>::iterator it = d.begin(); it < d.end(); it++) cout << *it; cout << endl; //输出:862 return 0; }
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
如何在没有core文件的情况下用dmesg+addr2line定位段错误
用QT制作3D点云显示器——QtDataVisualization
网友评论