I'm creating a Binary Search Tree and I want to implement inorder traversal using recursion for which I need to pass in root value which in this case is self.root
.
class BST:
def __init__(self):
self.root = None
def inOrder(self, root):
if root == None:
return
self.inOrder(root.left)
print(root.data, end=" ")
self.inOrder(root.right)
How do I pass root
's default value to be equal to self.root
?
If I use:
class BST:
def __init__(self):
self.root = None
def inOrder(self, root = self.root):
if root == None:
return
self.inOrder(root.left)
print(root.data, end=" ")
self.inOrder(root.right)
It shows error that self is not defined
.