Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. public static bool IsRightSmallANDLeftBig(BinNode<int> Head)
  2. {
  3. if (Head == null)
  4. return false; // no leaves and no parent.
  5.  
  6. if (IsLeaf(Head))
  7. return false; // head is a leaf, so there is no parent.
  8.  
  9. var right = Head.GetRight();
  10. var left = Head.GetLeft();
  11.  
  12. if (left != null)
  13. {
  14. if (left.GetValue() < Head.GetValue())
  15. return true;
  16. else if (!IsRightSmallANDLeftBig(left))
  17. return false;
  18. }
  19. if (right != null)
  20. {
  21. if (right.GetValue() > Head.GetValue())
  22. return true;
  23. else if (!IsRightSmallANDLeftBig(right))
  24. return false;
  25. }
  26.  
  27. return true;
  28.  
  29. }
  30.  
  31. public static bool IsRightSmallANDLeftBig(BinNode<int> Head)
  32. {
  33. if (Head == null)
  34. return false; // no leaves and no parent ~null~.
  35.  
  36. var right = Head.GetRight();
  37. var left = Head.GetLeft();
  38. if (left == null && right == null)
  39. return false;
  40. if (left == null && right != null)
  41. return IsRightSmallANDLeftBig(right);
  42. if (left != null && right == null)
  43. return IsRightSmallANDLeftBig(left);
  44. if (left != null && right != null)
  45. {
  46. if (left.GetValue() > Head.GetValue() && right.GetValue() < Head.GetValue())
  47. {
  48. return IsRightSmallANDLeftBig(left) && IsRightSmallANDLeftBig(right);
  49. }
  50. }
  51.  
  52. return false;
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement