c++stack + queue 模板
作者:野牛程序员:2025-11-10 09:28:31C++阅读 2234
c++stack + queue 模板
stack + queue 模板
✅ C++98 模板
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
// ====== stack ======
stack<int> st;
st.push(10);
st.push(20);
st.push(30);
// 栈顶是 30
while(!st.empty()){
cout << st.top() << " ";
st.pop();
}
cout << "\n";
// ====== queue ======
queue<int> q;
q.push(10);
q.push(20);
q.push(30);
// 队头是 10,FIFO
while(!q.empty()){
cout << q.front() << " ";
q.pop();
}
cout << "\n";
return 0;
}✅ 输入样例
(无输入)
✅ 输出样例
30 20 10 10 20 30
野牛程序员教少儿编程与信息学奥赛-微信|电话:15892516892

