# Python program to insert element in binary tree classnewNode():
def__init__(self, data):
self.key = data
self.left = None
self.right = None
""" Inorder traversal of a binary tree"""
definorder(temp):
if (not temp):
returninorder(temp.left)
print(temp.key,end =" ")
inorder(temp.right)
"""function to insert element in binary tree """
definsert(temp,key):
if not temp:
root =newNode(key)
return
q = []
q.append(temp)
# Do level order traversal until we find # an empty place. while (len(q)):
temp = q[0]
q.pop(0)
if (not temp.left):
temp.left =newNode(key)
breakelse:
q.append(temp.left)
if (not temp.right):
temp.right =newNode(key)
breakelse:
q.append(temp.right)
# Driver code if __name__ =='__main__':
root =newNode(10)
root.left =newNode(11)
root.left.left =newNode(7)
root.right =newNode(9)
root.right.left =newNode(15)
root.right.right =newNode(8)
print("Inorder traversal before insertion:", end =" ")
inorder(root)
key =12insert(root, key)
print()
print("Inorder traversal after insertion:", end =" ")
inorder(root)
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems
resetting your password contact us
Check Your Email and Click on the link sent to your email