data structures - need help in python list -


i implementing linked list in python. insert operation giving error below. can 1 in fixing ? list have head first node. subsequent nodes appended in insert operation.

output:

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() not none:                 current = current.get_nextnode           current.set_nextnode(node(data))     def display(self):        current = self.head        while current 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() 

on line:

current = current.get_nextnode 

you're missing parenthesis meaning "call function", here your're binding function current variable, leading next 'function' object has no attribute 'get_data'.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo