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

python linkedlist deletebyvalue method 这个方法有问题 #231

Open
sy1217209 opened this issue Jan 12, 2019 · 0 comments
Open

python linkedlist deletebyvalue method 这个方法有问题 #231

sy1217209 opened this issue Jan 12, 2019 · 0 comments

Comments

@sy1217209
Copy link

当链表当中self.__head.next 为None时,while循环调用node.next.data就会出错

`def delete_by_value(self, value):
'''在链表中删除指定存储数据的Node节点.
参数:
value:指定的存储数据
'''
if self.__head == None: # 如果链表是空的,则什么都不做
return

    if self.__head.data == value:  # 如果链表的头Node节点就是指定删除的Node节点
        self.__head = self.__head.next

    pro = self.__head
    node = self.__head.next
    not_found = False
    while node.data != value:
        if node.next == None:  # 如果已经到链表的最后一个节点,则表明该链表中没有找到执行Value值的Node节点
            not_found == True
            break
        else:
            pro = node
            node = node.next
    if not_found == False:
        pro.next = node.next

`

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

1 participant