标签:tor include out 双端队列 end stream for mil 下标
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; }
标签:tor include out 双端队列 end stream for mil 下标
原文地址:https://www.cnblogs.com/love-ziji/p/12797808.html