RSS Forums RSS

Binary Tree - Next Highest Value

Please support our C# advertiser: DiscountASP.NET – 3 Months Free on C# Web Hosting
Reply
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

  #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.
AddThis Social Bookmark Button
Reply With Quote  
Posts: 1,157
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 133
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Binary Tree - Next Highest Value

  #2  
Nov 18th, 2008
show us your code and we can help you out
Custom Application & Software Development
www.houseshark.net
Reply With Quote  
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

  #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  
Posts: 1,157
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 133
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Binary Tree - Next Highest Value

  #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  
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

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

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 
Last edited by mapidea : Nov 18th, 2008 at 9:19 am.
Reply With Quote  
Posts: 1,157
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 133
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Binary Tree - Next Highest Value

  #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  
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

  #7  
Nov 18th, 2008
How can I start to convert the code in C# and test it?
Reply With Quote  
Posts: 1,157
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 133
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Binary Tree - Next Highest Value

  #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  
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

  #9  
Nov 18th, 2008
How will you write

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

in C#
Reply With Quote  
Posts: 1,157
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 133
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Binary Tree - Next Highest Value

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Similar Threads
Other Threads in the C# Forum
Views: 984 | Replies: 11 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 3:16 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC