943,647 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 2055
  • C# RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Nov 18th, 2008
0

Re: Binary Tree - Next Highest Value

I have a binary tree

50

30 70

10 40 60 80

The below code is not giving the correct result for test cases 80, 83, 60, 11



C# Syntax (Toggle Plain Text)
  1.  
  2. public partial class Default2 : System.Web.UI.Page
  3. {
  4.  
  5. public class FindNextHighestNuber
  6. {
  7. public int search(int InputNumber)
  8. {
  9. int NextHighestNuber = "";
  10. int NodeValue = this.RootNode.value;
  11.  
  12. ActionOnNode(NodeValue, InputNumber);
  13.  
  14. }
  15.  
  16. public int ActionOnNode(int NodeValue, int InputNumber)
  17. {
  18. if (NodeValue <= InputNumber)
  19. {
  20. if (this.RightChild.value != "")
  21. {
  22. NodeValue = this.RightChild.value;
  23. ActionOnNode(NodeValue, InputNumber);
  24. }
  25. else
  26. {
  27. return this.Parent.value;
  28. }
  29. }
  30. else
  31. {
  32. if (this.LeftChild.value != "")
  33. {
  34. NodeValue = this.LeftChild.value;
  35. ActionOnNode(NodeValue, InputNumber);
  36. }
  37. else
  38. {
  39. return this.LeftChild.value;
  40. }
  41. }
  42. }
  43. }
  44. }
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

We have a binary tree

50
30 70

10 40 60 80


The following code doesn't work for 80, 83 , 60, 40


C# Syntax (Toggle Plain Text)
  1. public partial class Default2 : System.Web.UI.Page
  2. {
  3.  
  4. public class FindNextHighestNuber
  5. {
  6. public int search(int InputNumber)
  7. {
  8. int NextHighestNuber = "";
  9. int NodeValue = this.RootNode.value;
  10.  
  11. ActionOnNode(NodeValue, InputNumber);
  12.  
  13. }
  14.  
  15. public int ActionOnNode(int NodeValue, int InputNumber)
  16. {
  17. if (NodeValue <= InputNumber)
  18. {
  19. if (this.RightChild.value != "")
  20. {
  21. NodeValue = this.RightChild.value;
  22. ActionOnNode(NodeValue, InputNumber);
  23. }
  24. else
  25. {
  26. return this.Parent.value;
  27. }
  28. }
  29. else
  30. {
  31. if (this.LeftChild.value != "")
  32. {
  33. NodeValue = this.LeftChild.value;
  34. ActionOnNode(NodeValue, InputNumber);
  35. }
  36. else
  37. {
  38. return this.LeftChild.value;
  39. }
  40. }
  41. }
  42. }
  43. }
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mapidea is offline Offline
10 posts
since Nov 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