Я пытаюсь реализовать простой связанный список, но получаю следующее исключение: AttributeError: у объекта 'function' нет атрибута 'get_next'.
вот мой код:
class Lista:
def __init__(self):
self.root = None
self.len_l = 0
def __str__(self):
if not self.len_l:
return "::EMPTY::"
lista_c = ""
next_node = self.root
while next_node:
if next_node.get_next():
if type(next_node.get_datos()) != str:
lista_c += "%s -> "%(next_node.get_datos())
else:
lista_c += "'%s' -> "%(next_node.get_datos())
else:
if type(next_node.get_datos()) != str:
lista_c += " %s"%(next_node.get_datos())
else:
lista_c += " '%s'"%(next_node.get_datos())
next_node = next_node.get_next()
return lista_c
def add(self, dato):
self.root = nodo(dato,self.root)
self.len_l += 1
def find(self,dato):
if not self.len_l:
raise LSLexception("empty list")
this_node = self.root
while this_node.get_next():
if dato == this_node.get_datos():
return this_node
this_node = this_node.get_next()
return -1
def Valid_pos(self,pos):
if self.len_l == 0:
raise LSLexception("empty list")
if pos not in range(0,self.len_l):
raise LSLexception("data overflow")
def remove(self,dato):
if not self.len_l:
raise LSLexception("empty list")
if self.root.get_datos() == dato:
self.root = self.root.get_next()
previous_node = self.root
this_node = previous_node.get_next()
while this_node.get_next():
if this_node.get_datos() == dato:
previous_node.set_next(this_node.get_next())
return this_node
else:
previous_node = this_node
this_node = previous_node.get_next()
return -1
Проблема возникает в функции удаления в этой строке while this_node.get_next():
, но я использую ту же самую строку в функции "найти" I. Работает нормально, есть идеи? Для колледжа, поэтому есть некоторые вещи, которые я не могу изменить.