Python单向循环链表节点删除
def delete(self, data):
if not self.head:
return
if self.head.data == data:
current = self.head
while current.next != self.head:
current = current.next
if current == self.head:
self.head = None
else:
current.next = self.head.next
self.head = current.next
else:
current = self.head
while current.next != self.head:
if current.next.data == data:
current.next = current.next.next
return
current = current.next
用户评论