'''
This is an binary search tree
@author: Djra (http://stackoverflow.com/users/2805357/djra)
@author: Anh Nguyen
@version: Nov-15-2016
'''

class Node:
    def __init__(self,val):
        self.l = None
        self.r = None
        self.v = val
class Tree:
    def __init__(self):
        self.root = None
    def getRoot(self):
        return self.root
    def add(self,val):
        if(self.root == None):
            self.root = val
        else:
            self._add(val,self.root)
    def _add(self,val,node):
        if (val < node.v):
            if(node.l is not None):
                self._add(val,node.l)
            else:
                node.l = Node(val)
        else:
            if (node.r is not None):
                self._add(val.node.r)
            else:
                node.r = Node(val)
    def find(self,val):
        if (self.root is not None):
            return self._find(val,self.root)
        else:
            return None
    def _find(self, val, node):
        if(val == node.v):
            return node
        elif(val < node.v and node.l is not None):
            self._find(val, node.l)
        elif(val > node.v and node.r is not None):
            self._find(val, node.r)
    def deleteTree(self):
        self.root = None
    def printTree(self):
        while(self.root is not None):
            self._printTree(self.root)
    def _printTree(self,node):
        if (node is not None):
            self._printTree(node.l)
            print( node.v , ' ')
            self._printTree(node.r)
