#!/usr/bin/env python
# fonte: http://rebrained.com/?p=17
# busca binĂ¡ria em python

def binarySearch(node,value):
    """
    >>> node1=Node(1)
    >>> node4=Node(4)
    >>> node3=Node(3,node1,node4)
    >>> node7=Node(7)
    >>> node5=Node(5,node3,node7)
    >>> binarySearch(node5,4)
    5 3 4
    >>> binarySearch(node5,5)
    5
    """
    print node.value,
    if value==node.value: return
    if value<node.value:
        binarySearch(node.left,value)
    else:
        binarySearch(node.right,value)
    return None

class Node:
    def __init__(self,value,left=None,right=None):
    	self.value=value;self.left=left;self.right=right

if __name__ == "__main__":
    import doctest
    doctest.testmod()