My own class methods do not work when I check how my function 'linker' operates. These methods return None value.
When I run these methods in the interactive mode, they work and each returns a new node linked to the root. Why do these methods not work when I run the function 'linker'?
class node:
def init(self, data):
self.data = data
self.left = None
self.right = None
def insertL(self, data):
self.left = node(data)
return self.left
def insertR(self, data):
self.right = node(data)
return self.right
def linker(root, lst): import randomseq = ['left', 'right', 'nither', 'either'] res = random.choices(seq,(0.1,0.3,0.1,0.6), k=1) if lst: l=random.choice(lst) if res == 'left': root=root.insertL(l) lst.remove(l) return root, lst elif res == 'right': root=root.insertR(l) lst.remove(l) return root,lst elif res == 'nither': return root,lst elif res == 'either': nodes = [root.insertL(l)] lst.remove(l) l2=random.choice(lst) nodes+=[root.insertR(l2)] lst.remove(l2) return nodes, lst else: return root, lst
Aucun commentaire:
Enregistrer un commentaire