if current is None:
        return None

    while ((s.is_empty() is not True) or (current is not None)):
        if current is not None:
            s.push(current)
            current = current.left
        else:
            current = s.get_top()
            s.pop()
            print " --> " + str(current.value)
            current = current.right
            

if __name__ == '__main__':

    t = Tree()

    t.add(5)
    t.add(2)
    t.add(4)
    t.add(1)
    t.add(7)
    t.add(6)
    t.add(8)

    t.print_tree()

    inorder(t)
Example #2
0
from bst import Tree

tree = Tree()
tree.add(2)
tree.add(3)
tree.add(1)
tree.print_tree()
        node.value = 0
    if node is not None:    
        _delete(node.left)
        _delete(node.right)
        node.value = 0

def delete(tree):
    if tree is None:
        return None 

    if tree:
       tree.get_root().value = 0 
    
    _delete(tree.get_root())   

if __name__ == '__main__':
    t1 = Tree()
    t1.add(2)
    t1.add(1)
    t1.add(3)
    t1.add(5)
    t1.add(4)
    t1.add(6)


    t1.print_tree()

    delete(t1)

    t1.print_tree()