我在python中实现了一个链表。但是我的插入操作给出了以下错误。任何人都可以帮忙解决这个问题吗?我的列表将作为第一个节点。后续节点将在插入操作中追加。
输出:
10
Traceback (most recent call last):
File "z.py", line 45, in <module>
list_mgmt()
File "z.py", line 43, in list_mgmt
ll.display()
File "z.py", line 32, in display
print current.get_data()
AttributeError: 'function' object has no attribute 'get_data'
class Node:
def __init__(self, data):
self.data = data
self.nextnode = None
def get_data(self):
return self.data
def get_nextnode(self):
return self.nextnode
def set_nextnode(self, node):
self.nextnode = node
class LinkList:
def __init__(self):
self.head = None
def insert(self, data):
if self.head == None:
current = Node(data)
self.head = current
else:
current = self.head
while current.get_nextnode() is not None:
current = current.get_nextnode
current.set_nextnode(Node(data))
def display(self):
current = self.head
while current is not None:
print current.get_data()
current = current.get_nextnode
#def delete(self, data):
#def size(self):
#def search(self, data):
def list_mgmt():
ll = LinkList()
ll.insert(10)
ll.insert(20)
ll.display()
list_mgmt()
答案 0 :(得分:0)
在线:
current = current.get_nextnode
您缺少括号含义&#34;调用该函数&#34;,此处您只是将函数绑定到current
变量,显然导致下一个'function' object has no attribute 'get_data'
}。