Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- t = {'value': 4, 'left': {'value': 2, 'left': {'value': 1, 'left': None, 'right': None}, 'right': {'value': 3, 'left': None, 'right': None}}, 'right': {'value': 7, 'left': {'value': 5, 'left': None, 'right': None}, 'right': None}}
- def add_node_to_bin_src_tree(tree, new_node):
- if tree is None:
- return new_node
- if tree['value'] == new_node['value']:
- return tree
- if new_node['value'] < tree['value']:
- tree['left'] = add_node_to_bin_src_tree(tree['left'], new_node)
- else:
- tree['right'] = add_node_to_bin_src_tree(tree['right'], new_node)
- return tree
- print(add_node_to_bin_src_tree(t, {'value': 5, 'left': None, 'right': None}))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement