__author__ = 'nitin'
def find_inorder_succ(node):
if node is not None:
if node.getRootVal() is None and node.getRightChild() is not None:
p=left_most_child(node.getRightChild())
else:
p=node
while p.getRootVal() is not None:
if p.getLeftChild()==node:
break
node=node.getRootVal()
p=node
return p
return None
def left_most_child(node):
if node is None:
return None
while node.getLeftChild() is not None:
node=node.getLeftChild()
return node
def find_inorder_succ(node):
if node is not None:
if node.getRootVal() is None and node.getRightChild() is not None:
p=left_most_child(node.getRightChild())
else:
p=node
while p.getRootVal() is not None:
if p.getLeftChild()==node:
break
node=node.getRootVal()
p=node
return p
return None
def left_most_child(node):
if node is None:
return None
while node.getLeftChild() is not None:
node=node.getLeftChild()
return node
No comments:
Post a Comment