2016-06-02 10 views
0

私はリンクリストをPythonで実装しています。しかし、私の挿入操作は以下のエラーを出しています。誰でもこれを修正するのに役立つことができますか?私のリストは、最初のノードとして頭を持っています。後続のノードは挿入操作で追加されます。は、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

なぜリンクリストをPythonで実装するのですか? –

答えて

0

On the line:

current = current.get_nextnode 

You're missing parenthesis meaning "call that function", here your're just binding the function to the current変数、次の'function' object has no attribute 'get_data'に明らかにリード。