1.二分搜索树实现:
class BSTMap:
class _Node:
def __init__(self,key=None,value=None):
self.key=key
self.value=value
self.left=None
self.right=None
def __str__(self):
return "key:{},Value:{}".format(str(self.key),str(self.value))
def __init__(self):
self._size=0
self._root=None
def get_size(self):
return self._size
def add(self,key,value):
self._root=self._add(self._root,key,value)
def _add(self,node,key,value):
if not node:
self._size+=1
node=self._Node(key,value)
elif node.key==key:
node.value=value
elif node.key>key:
node.left=self._add(node.left,key,value)
else node.key<key:
node.right=self._add(node.right,key,va