1
def delete_node(head, value):
p=head
if p is None:
return None
while p.value!=value:
p=p.next
if p.next is head and p.value!=value:
return head
p.value=p.next.value
if p.next==head:
head=p
p.next=p.next.next
return head
上面是我的代码,用于根据节点的值删除一个循环链表中的节点! 该代码不会给我这种情况的结果 - 我只有1个元素在列表中,我删除了它。所以结果应该是一个空集。但是因为我把p.value = p.next 。值它再次指向自身,并且列表中的值相同!谁能帮我吗!感谢提前! :)Python中的循环链表
Ty ..只要放一个if循环!适用于所有情况! :) – user2205015