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

fix a bug in linked_list.py #21

Merged
merged 1 commit into from
Oct 20, 2019
Merged

Conversation

ttigong
Copy link
Contributor

@ttigong ttigong commented Jul 7, 2019

您好!我刚刚开始学习您的《Python 算法与数据结构视频教程》,现在只是看程序,还没看视频。在“单链表”的程序“linked_list.py”里面,我发现一处bug,就是在删除链表中的某个节点时,如果这个链表就剩这一个节点了,也就是该节点是第一个,也是最后一个节点的时候,会出现 self.tailnode = prevnode = self.root 的情况,而本来应该为 self.tailnode = None 的,这会造成一些问题。

我写了测试代码,如下图所示,可以发现其中的问题。
1

换成修改后的代码,问题不会再出现,如下图所示。
2

@PegasusWang
Copy link
Owner

感谢指出,已经合并。

@PegasusWang PegasusWang merged commit 9ad4e86 into PegasusWang:master Oct 20, 2019
@PegasusWang
Copy link
Owner

增加测试用例:

def test_single_node():
    ll = LinkedList()
    ll.append(0)
    ll.remove(0)
    ll.appendleft(1)
    assert list(ll) == [1]

PegasusWang added a commit that referenced this pull request Oct 20, 2019
@ttigong ttigong deleted the fixbug branch December 21, 2019 13:06
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.

2 participants