Python Binary SearchTree

时间:2017-01-20 10:59:41

标签: python-3.x binary-search-tree

class SearchTree:
   def __init__(self, items = None):         
       if items:
         self.tree = [None, None, None]
         for item in items:
             self.add(item)
     else:
         return None
  def add(self, item):
     if self.tree[2] == None:
         self.tree[2] = item
     if self.tree[2] > item:
         self.tree[0] = self .add(item)
     if self.tree[2] < item:
         self.tree[1] = self.add(item)
     elif self.tree[2] == item:
         pass
     return self.tree
if __name__ == "__main__":
 a = [1,2,3]
 b = SearchTree(a)

为什么我要保持一个RecursionError?在课堂上我仍然是一名新秀,但我无法弄清楚......

0 个答案:

没有答案