return has_key(node.right, key)

def floor_ceil(node, key, floor, ceil):
    while node:
        if node.value == key:
            floor = node
            ceil = node
        elif key < node.value:
            ceil = node
            node = node.left
        else:
            floor = node
            node = node.right

if __name__=='__main__':

    t = Tree()

    t.add(6)
    t.add(2)
    t.add(3)
    t.add(9)
    t.add(7)

    t.print_tree()

    floor = None
    ceil = None
    floor_ceil(t.get_root(),1,floor,ceil)
    print floor, ceil
    node.value = bst[index]
    print node.value
    index = index + 1
    convert_to_bst(node.right,index)

def to_list(node):
    if node is None:
        return

    to_list(node.left)
    bst.append(node.value)
    to_list(node.right)


if __name__ == '__main__':
    t = Tree()

    t.add(5)
    t.add(3)
    t.add(6)
    t.add(9)
    t.add(2)
    t.add(4)

    t.print_tree()

    to_list(t.get_root())
    qsort(bst)
    index = 0
    convert_to_bst(t.get_root(),index)
#/usr/bin/python
from bst import Tree

def min_depth(node):
    if node is None:
        return min_depth 
    if node.left is None and node.right is None:
        return 1
    if node.left is not None:
        min_left = min_depth(node.left)
    if node.right is not None:
        min_right = min_depth(node.right)
    return min(min_left, min_right) + 1


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


    print min_depth(t.get_root())

        node = None
    elif node.left is None or node.right is None:
        print "delete case 2"    
        if node.left is not None:
            node.value = node.left.value
            node.left = None
        if node.right is not None:
            node.value = node.right.value
            node.right = None    
    elif node.left is not None and node.right is not None:
         print "delete case 3"    
         inorder_node = inorder_successor(node)
         print inorder_node.value
         node.value = inorder_node.value
         inorder_node.value = 0
            

if __name__ == '__main__':
    t = Tree()

    t.add(5)
    t.add(3)
    t.add(4)
    t.add(1)
    t.add(8)
    t.add(6)

    t.print_tree()
    delete_node(t.get_root(), 5)
    t.print_tree()
def preorder(node):
    
    if node is None:
        return None
    
    print node.value
    preorder(node.left)
    preorder(node.right)

    return


if __name__ == '__main__':
    t = Tree()

    t.add(5)
    t.add(8)
    t.add(2)
    t.add(3)
    t.add(1)
    t.add(6)
    t.add(9)


    t.print_tree()

    print "-- Preorder -- "
    preorder(t.get_root())
    print "-- End -- "