View Single Post
Join Date: Nov 2008
Posts: 10
Reputation: mapidea is an unknown quantity at this point 
Solved Threads: 0
mapidea mapidea is offline Offline
Newbie Poster

Re: Binary Tree - Next Highest Value

 
0
  #5
Nov 18th, 2008
I have not done this in C#.

  1.  
  2. int findSuccessor(self):
  3. succ = None
  4. if self.rightChild:
  5. succ = self.rightChild.findMin()
  6. else:
  7. if self.parent.leftChild == self:
  8. succ = self.parent
  9. else:
  10. self.parent.rightChild = None
  11. succ = self.parent.findSuccessor()
  12. self.parent.rightChild = self
  13. return succ
  14.  
  15. int findMin(self):
  16. n = self
  17. while n.leftChild:
  18. n = n.leftChild
  19. print 'found min, key = ', n.key
  20. return n
Last edited by mapidea; Nov 18th, 2008 at 10:19 am.
Reply With Quote