''' mbinary ######################################################################### # File : binaryTree.py # Author: mbinary # Mail: zhuheqin1@gmail.com # Blog: https://mbinary.coding.me # Github: https://github.com/mbinary # Created Time: 2018-05-19 23:07 # Description: ######################################################################### ''' from functools import total_ordering @total_ordering class node: def __init__(self,val,left=None,right=None,freq = 1): self.val=val self.left=left self.right=right self.freq = freq def __lt__(self,nd): return self.valnewNode: if nd.left is None:nd.left = newNode else : _add(nd.left,newNode) else:nd.freq +=1 _add(self.root,node(val)) def find(self,val): prt= self._findPrt(self.root,node(val),None) if prt.left and prt.left.val==val: return prt.left elif prt.right and prt.right.val==val:return prt.right else :return None def _findPrt(self,nd,tgt,prt): if nd==tgt or nd is None:return prt elif nd