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
相關文章
相關標籤/搜索