Advertisement
STANAANDREY

src in bin src tree

Nov 18th, 2022
1,085
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. t = {'value': 4, 'left': {'value': 2, 'left': {'value': 1, 'left': None, 'right': None},
  2.                           'right': {'value': 3, 'left': None, 'right': None}},
  3.      'right': {'value': 7, 'left': {'value': 5, 'left': None, 'right': None}, 'right': None}}
  4.  
  5.  
  6. def src_in_bin_src_tree(tree, x):
  7.     if tree is None:
  8.         return False
  9.  
  10.     if tree['value'] == x:
  11.         return True
  12.  
  13.     if x < tree['value']:
  14.         return src_in_bin_src_tree(tree['left'], x)
  15.     else:
  16.         return src_in_bin_src_tree(tree['right'], x)
  17.  
  18.  
  19. print(src_in_bin_src_tree(t, 5))
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement