Advertisement
STANAANDREY

PRINT BIN TREE LEAFEs

Nov 18th, 2022 (edited)
759
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. binary_tree = { "value" : 2, "left":
  2.             {
  3.                 "value": 7, "left": None, "right":
  4.                 {
  5.                     "value": 6, "left":
  6.                     {
  7.                         "value": 5, "left": None, "right": None
  8.                     }, "right":
  9.                     {
  10.                         "value":11, "left": None, "right": None
  11.                     },
  12.                 },
  13.             }, "right":
  14.                 {
  15.                     "value": 5, "left": None, "right": None
  16.                 }
  17.         }
  18.  
  19. def get_leafes(tree):
  20.     if tree == None:
  21.         return
  22.  
  23.     get_leafes(tree["left"])
  24.     if tree['left'] == None and tree['right'] == None:
  25.         print(tree['value'])
  26.     get_leafes(tree["right"])
  27.  
  28.  
  29. print(get_leafes(binary_tree))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement