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

修复了javaScript中出队的问题 #540

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

leonaron0410
Copy link

在链表实现的队列中,当你删除最后一个元素时,head 应该设置为 null,但 tail 没有被更新为 null。因此,虽然队列为空,但 tail 仍然指向一个已删除的节点,可能会导致意外的行为或者访问错误。

正确的行为:
当队列只剩一个元素时:head 和 tail 应该指向同一个节点。
出队后,当队列为空时:head 和 tail 都应该变为 null,表示队列为空。
代码修复:
我们需要在 dequeue 方法中检查是否移除的是队列中的最后一个元素,如果是,确保同时将 head 和 tail 都设置为 null。

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

Successfully merging this pull request may close these issues.

1 participant