C++--堆栈和队列
最编程
2024-10-07 14:53:18
...
1.简介
栈和队列的定义和之前的容器有所差别
2.简单地使用
void test_stack1()
{
stack<int> st;
st.push(1);
st.push(2);
st.push(3);
st.push(4);
while (!st.empty())
{
cout << st.top() << " ";
st.pop();
}
cout << endl;
}
void test_queue1()
{
queue<int> q;
q.push(1);
q.push(2);
q.push(3);
q.push(4);
while (!q.empty())
{
cout << q.front() << " ";
q.pop();
}
cout << endl;
}
3.练习题
1.232. 用栈实现队列 - 力扣(LeetCode)
2.155. 最小栈 - 力扣(LeetCode)
3.栈的压入、弹出序列_牛客题霸_牛客网 (nowcoder.com)
4.102. 二叉树的层序遍历 - 力扣(LeetCode)
5.150. 逆波兰表达式求值 - 力扣(LeetCode)
运算符的优先级顺序是由相邻两个运算符的优先级决定的
后缀表达式没有括号,括号是加强优先级的
上一篇: 背筋膜炎的症状和治疗方法
下一篇: 查看 ----IP 交流流程