Binary Tree - Next Highest Value

Please support our C# advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
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

Re: Binary Tree - Next Highest Value

 
0
  #11
Nov 18th, 2008
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



  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. }
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
  #12
Nov 18th, 2008
We have a binary tree

50
30 70

10 40 60 80


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


  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. }
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