![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
队列
队列
CervoLu
这个作者很懒,什么都没留下…
展开
-
102二叉树的层序遍历
层序遍历通过一个 队列实现,循环直到队列为空为止 #include<iostream> #include<queue> #include<vector> using namespace std; struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode() : val(0), left(nullptr), right(nullptr) {} TreeNo原创 2021-11-23 23:49:45 · 60 阅读 · 1 评论 -
232用栈实现队列
我有一个问题一开始没反应过来,就是s2的栈顶一定是队列队头的。如果s2空了,s1会把全部元素转到s2 #include<iostream> #include<stack> using namespace std; class MyQueue { private: stack<int>s1, s2; void intoout() { while (!s1.empty()) { s2.push(s1.top());原创 2021-11-21 15:58:19 · 437 阅读 · 0 评论