Reputation: 361
I am a programming beginner, and want to improve my skills. So I decided to implement some algorithms; i.e. I implemented a class BTree(object)
which represents a binary search tree . I struggle with recursive methods. I tried to code a method minEl(self)
which should return the min element of the tree, but each time I call the method, the following error occurs:
minEl()
takes 1 positional argument but 2 were given.
I am gratefull for any help.
Well here is my code:
class BTree(object):
'Modelliert einen binären Suchbaum mit mehreren nützlichen Methoden'
def __init__ (self, key, ltree = None, rtree = None, val = None, ):
self.ltree = ltree
self.rtree = rtree
self.key = key
self.val = val
def minEl(self):
if self.ltree == None:
return self.key
else:
return self.minEl(self.ltree)
Upvotes: 0
Views: 46
Reputation: 2981
self argument is the object on which you call a method (the object before dot).
I think:
self.ltree.minEl()
is what you want instead of self.minEl(self.ltree).
Upvotes: 3