【发布时间】:2018-01-19 10:17:15
【问题描述】:
方法从谷歌上得到并稍作改动:
def removeNodeAtPosition(self, position):
if self.head == None:
print("List is empty")
return
current = self.head
if position == 0:
self.head = current.next
current = None
self.size-=1
return
for i in range(position-1):
current = current.next
if current == None:
break
if current == None:
return
if current.next == None:
return
next = current.next.next
current.next = None
current.next = next
if position == self.size: #two lines here used for updating self.tail
self.tail = current
self.size-=1
标题主要是这样说的:当我用这种方法删除节点的尾部时,我的 self.tail 值没有改变。我不知道我的两行代码的位置是否出错,或者代码是否错误。我已经完好无损地保留了最近的尝试。任何解决此问题的帮助将不胜感激。
【问题讨论】:
标签: python data-structures linked-list nodes singly-linked-list