Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Node:
- def __init__(self, v, l, r):
- self.v = v
- self.l = l
- self.r = r
- t4 = Node(4, None, None);
- t5 = Node(5, None, None);
- t2 = Node(2, t4, t5);
- t6 = Node(6, None, None);
- t7 = Node(7, None, None);
- t3 = Node(3, t6, t7);
- t1 = Node(1, t2, t3);
- stack = [("v", t1)]
- while len(stack) >= 1:
- (x, top) = stack.pop()
- if (x == "v"):
- if top.r != None: stack.append(("v", top.r))
- stack.append ((("p", top)))
- if top.l != None: stack.append(("v", top.l))
- if (x == "p"):
- print top.v
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement