LeetCode 232 Implement Queue using Stacks && 225 Implement Stack using Queues

1.用栈表示一个队列 思路:使用两个栈表示,一个栈叫push_stack,一个叫pop_stack,我们只往push_stack中加入新数据,只从pop_stack中取出数据。加入数据,没有什么约束条件;取出数据时候,因为队列是先进先出,所以把push_stack中的内容取出放入到pop_stack中就可以了。但是要注意,必须要判断pop_stack为空,才可以往pop_stack中加入pop_s
相关文章
相关标签/搜索