Advertisement
Guest User

Untitled

a guest
Jan 29th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. class Node:
  2. def __init__(self, v, l, r):
  3. self.v = v
  4. self.l = l
  5. self.r = r
  6.  
  7. t4 = Node(4, None, None);
  8. t5 = Node(5, None, None);
  9. t2 = Node(2, t4, t5);
  10. t6 = Node(6, None, None);
  11. t7 = Node(7, None, None);
  12. t3 = Node(3, t6, t7);
  13. t1 = Node(1, t2, t3);
  14. stack = [("v", t1)]
  15.  
  16. while len(stack) >= 1:
  17. (x, top) = stack.pop()
  18. if (x == "v"):
  19. if top.r != None: stack.append(("v", top.r))
  20. stack.append ((("p", top)))
  21. if top.l != None: stack.append(("v", top.l))
  22. if (x == "p"):
  23. print top.v
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement