def putValueInBST(root, val): # assuming the val = 7 which is max of all the existing node values in BST
if root is None:
root = Node(val)
elif val > root.data:
putValueInBST(root.right, val)
else:
putValueInBST(root.left, val)
def put_val_manually(r, val):
r.right.right = Node(val)
(of course in the put_val_manually()
function, i am doing it directly.)
The full code is here: https://i.ibb.co/yf2YTYy/code.png
Try to return the node
def putValueInBST(root, val): # assuming the val = 7 which is max of all the existing node values in BST
if root is None:
return Node(val)
elif val > root.data:
root.right=putValueInBST(root.right, val)
else:
root.left=putValueInBST(root.left, val)
root=putValueInBST(root,val)
This code works
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.