Binary Tree - Next Highest Value

Please support our C# advertiser: Intel Parallel Studio Home
Reply

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

Binary Tree - Next Highest Value

 
0
  #1
Nov 18th, 2008
How can we find the next highest value in the binary tree?

We have a binary tree and an number is being input. We need to find the next highest number.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,160
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Binary Tree - Next Highest Value

 
0
  #2
Nov 18th, 2008
show us your code and we can help you out
Custom Application & Software Development
www.houseshark.net
Reply With Quote Quick reply to this message  
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
  #3
Nov 18th, 2008
What will be the C# version of the below code.

int findSuccessor(self):
succ = None
if self.rightChild:
succ = self.rightChild.findMin()
else:
if self.parent.leftChild == self:
succ = self.parent
else:
self.parent.rightChild = None
succ = self.parent.findSuccessor()
self.parent.rightChild = self
return succ

int findMin(self):
n = self
while n.leftChild:
n = n.leftChild
print 'found min, key = ', n.key
return n
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,160
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Binary Tree - Next Highest Value

 
0
  #4
Nov 18th, 2008
please put the code in code tags

do you have any of this done yourself in c# yet?
Custom Application & Software Development
www.houseshark.net
Reply With Quote Quick reply to this message  
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 Quick reply to this message  
Join Date: Aug 2008
Posts: 1,160
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Binary Tree - Next Highest Value

 
0
  #6
Nov 18th, 2008
then make an effort, and we will make an effort

if you are having trouble with a specific piece, rather than just though whole thing then let us know, we won't do the work for you
Custom Application & Software Development
www.houseshark.net
Reply With Quote Quick reply to this message  
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
  #7
Nov 18th, 2008
How can I start to convert the code in C# and test it?
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,160
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Binary Tree - Next Highest Value

 
0
  #8
Nov 18th, 2008
did you do it in python or is that some else's?

here's a link that will give you a java version

MAKE AN EFFORT
http://simpleprogrammingtutorials.co...t-overview.php
Custom Application & Software Development
www.houseshark.net
Reply With Quote Quick reply to this message  
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
  #9
Nov 18th, 2008
How will you write

  1. if self.rightChild:
  2. succ = self.rightChild.findMin()

in C#
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,160
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Binary Tree - Next Highest Value

 
0
  #10
Nov 18th, 2008
in c# you have classes, think of it this way

you have a node, and a node on the left and right

each node is connected to another node (rightChild) and (leftChild)

you can't just translate this code to c#, you need to think about what structure you need first
Custom Application & Software Development
www.houseshark.net
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC