我是python的初学者,现在我在这个程序中遇到了一个问题。
首先,这里是NodeList:<;-linklist
class Node:
def __init__(self,initdata):
self.data = initdata
self.next = None
def getData(self):
return self.data
def getNext(self):
return self.next
def setData(self,newdata):
self.data = newdata
def setNext(self,newnext):
self.next = newnext
下面是我的节目:
^{pr2}$当我在addFrontDLL中添加一个项目时,一切都很好。但是在addredll中添加一个项目后,它的类似项将添加到另一个容器中。然后我尝试再次使用addFrontDLL添加,它可以处理我想要的方式(该项添加到另一个容器上)。请参见下图:
我希望有人替我解释并解决。如有任何帮助,将不胜感激。非常感谢。
问题是,第一次添加前面有
addFrontDLL
的节点时,没有设置DequeLL.last
字段。您的addRearDLL
确实正确地处理了添加新节点的问题,这就是为什么在后面添加之后一切都会正常工作。在试试这个:
示例的输出现在是:
^{pr2}$相关问题 更多 >
编程相关推荐