I made two trees in python with two different instances of the same class. I need to access the method in the class now with both the instances(roots) with which i created two trees.
# To create a tree from scratch
class node:
"""To create nodes each time an instance has been
created"""
def __init__(self, key):
self.data = key
self.left = None
self.right = None
def issame(self,root1,root2):
if root1 or root2:
print(root1.data,root2.data)
self.issame(root1.left,root2.left)
"""To insert the data manually"""
##First Tree
root1 = node(10)
root1.left = node(20)
root1.right = node(30)
root1.left.left = node(50)
##Second Tree
root2 = node(20)
root2.left = node(20)
root2.right = node(30)
root2.left.left = node(50)
issame(root1,root2)
I read in some post that we can keep the issame function definition outside of the class and use self within. Now at the end if i call the function, it says issame
doesn't exist. Issame is used to check if leaf nodes of tree are same and the method is not fully developed as i faced the problem in first step.