自学内容网 自学内容网

C++——stack和queue

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)

运算符的优先级顺序是由相邻两个运算符的优先级决定的

后缀表达式没有括号,括号是加强优先级的


原文地址:https://blog.csdn.net/2301_80342122/article/details/142726076

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!