Guest User

Untitled

a guest
Oct 19th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. stack = []
  2.  
  3. def search(root, v):
  4. global stack
  5. stack.append(root.info)
  6. if root.info == v:
  7. print(stack)
  8. return
  9. if root.left is not None:
  10. search(root.left, v)
  11. if root.right is not None:
  12. search(root.right, v)
  13. stack.pop()
  14. pass
  15.  
  16. def lca(root, v1, v2):
  17. search(root,v1)
  18. print(stack)
  19.  
  20. [4, 2, 1]
  21. [4]
Add Comment
Please, Sign In to add comment