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

linked_list.py 中的remove操作仍然是错误的 #5

Closed
TillLindemann opened this issue May 31, 2018 · 1 comment
Closed

linked_list.py 中的remove操作仍然是错误的 #5

TillLindemann opened this issue May 31, 2018 · 1 comment

Comments

@TillLindemann
Copy link

很明显,你的prevnode并没有更新,从头到尾都是指向的根节点,这样的话,你每删除一个元素,实际上就是把这个元素前面的所有元素都删了,remove方法应该这样写:
def remove(self, value): # O(n)
""" 删除包含值的一个节点,将其前一个节点的 next 指向被查询节点的下一个即可
:param value:
"""
prevnode = self.root #
curnode = self.root.next
for curnode in self.iter_node():
if curnode.value == value:
prevnode.next = curnode.next
del curnode
self.length -= 1
return 1 # 表明删除成功
else:
prevnode = curnode
return -1 # 表明删除失败

@PegasusWang
Copy link
Owner

PegasusWang commented Jun 1, 2018

抱歉,已经修正。#3
这个 mr 我并没有仔细检查和调整单测就 merge 了。已经修改并且重新完善单测。感谢提出问题,后续我会修改讲义和重新剪辑视频相关内容。防止产生误导。

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