Ejemplo n.º 1
0
def post_order(node):
    st1 = Stack()
    st2 = Stack()
    if node != None: st1.push(node)
    while not st1.is_empty():
        n = st1.pop()
        st2.push(n)
        if n.left != None: st1.push(n.left)
        if n.right != None: st1.push(n.right)
    while not st2.is_empty():
        n = st2.pop()
        print(n.data, end=' ')
    print()
    return
Ejemplo n.º 2
0
def pre_order(node):
    stk = Stack()
    if node != None: stk.push(node)
    while not stk.is_empty():
        n = stk.pop()
        print(n.data, end=' ')
        if n.right != None: stk.push(n.right)
        if n.left != None: stk.push(n.left)
    print()
    return