Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

两个栈实现队列的问题 #5

Open
easternHong opened this issue Nov 24, 2017 · 1 comment
Open

两个栈实现队列的问题 #5

easternHong opened this issue Nov 24, 2017 · 1 comment

Comments

@easternHong
Copy link

void push(int node) { stackIn.push(node); } //不会导致队列顺序出错吗?

@yantanglife
Copy link

stackIn模拟入队,stackOut模拟出队。因此出队的时候,先判断stackOut是否为空,如果为空,则将stackIn的所有数据压栈到stackOut,此时stackOut栈顶元素就是模拟队列的头元素;如果不为空,就直接将stackOut栈顶元素出栈。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants