import random
class BSTnode(object):
def __init__(self, parent, t):
self.key = t
self.parent = parent
self.left = None
self.right = None
self.size = 1
def update_stats(self):
self.size = (0 if self.left is None else
self.left.size) + (0 if self.right is None else
self.right.size)
def insert(self, t, NodeType):
self.size += 1
if t < self.key:
if self.left is None:
131
self.left = NodeType(self, t)
return self.left
else:
return self.left.insert(t, NodeType)
Do'stlaringiz bilan baham: |