943,769 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 2060
  • C# RSS
You are currently viewing page 1 of this multi-page discussion thread
Nov 18th, 2008
0

Binary Tree - Next Highest Value

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mapidea is offline Offline
10 posts
since Nov 2008
Nov 18th, 2008
0

Re: Binary Tree - Next Highest Value

show us your code and we can help you out
Reputation Points: 133
Solved Threads: 141
Veteran Poster
dickersonka is offline Offline
1,162 posts
since Aug 2008
Nov 18th, 2008
0

Re: Binary Tree - Next Highest Value

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mapidea is offline Offline
10 posts
since Nov 2008
Nov 18th, 2008
0

Re: Binary Tree - Next Highest Value

please put the code in code tags

do you have any of this done yourself in c# yet?
Reputation Points: 133
Solved Threads: 141
Veteran Poster
dickersonka is offline Offline
1,162 posts
since Aug 2008
Nov 18th, 2008
0

Re: Binary Tree - Next Highest Value

I have not done this in C#.

C# Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mapidea is offline Offline
10 posts
since Nov 2008
Nov 18th, 2008
0

Re: Binary Tree - Next Highest Value

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
Reputation Points: 133
Solved Threads: 141
Veteran Poster
dickersonka is offline Offline
1,162 posts
since Aug 2008
Nov 18th, 2008
0

Re: Binary Tree - Next Highest Value

How can I start to convert the code in C# and test it?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mapidea is offline Offline
10 posts
since Nov 2008
Nov 18th, 2008
0

Re: Binary Tree - Next Highest Value

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
Reputation Points: 133
Solved Threads: 141
Veteran Poster
dickersonka is offline Offline
1,162 posts
since Aug 2008
Nov 18th, 2008
0

Re: Binary Tree - Next Highest Value

How will you write

C# Syntax (Toggle Plain Text)
  1. if self.rightChild:
  2. succ = self.rightChild.findMin()

in C#
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mapidea is offline Offline
10 posts
since Nov 2008
Nov 18th, 2008
0

Re: Binary Tree - Next Highest Value

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
Reputation Points: 133
Solved Threads: 141
Veteran Poster
dickersonka is offline Offline
1,162 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Theading problem
Next Thread in C# Forum Timeline: how i can fetch the from datagrid





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC