deque
push_front(): 从头部插入
pop_front(): 从头部弹出
template<typename T>
void info(const deque<T>& q) {
for (auto& x : q) {
cout << x << " ";
}
cout << endl;
}
void disp(const deque<int>& q) {
for (auto it = q.begin(); it != q.end(); it++) {
cout << *it << " ";
}
cout << endl;
}
int main(int argc, char const *argv[])
{
deque<int> q;
q.push_back(10);
q.push_back(11);
q.push_back(12);
q.push_front(9);
info(q);
q.pop_back();
q.pop_front();
disp(q);
return 0;
}
9 10 11 12
10 11
栈和队列
#include <iostream>
#include <stack>
#include <queue>
using namespace std;
int main(int argc, char const *argv[]) {
stack<int> st;
st.push(12);
st.push(34);
st.push(56);
while (!st.empty()) {
cout << st.top() << " ";
st.pop();
}
cout << endl;
queue<int> q;
q.push(14);
q.push(25);
q.push(36);
while (!q.empty()) {
cout << q.front() << " ";
q.pop();
}
cout << endl;
return 0;
}
56 34 12
14 25 36
优先队列
priority_queue<int> q;
q.push(14);
q.push(25);
q.push(36);
while (!q.empty()) {
cout << q.top() << " ";
q.pop();
}
cout << endl;
36 25 14