Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static bool IsRightSmallANDLeftBig(BinNode<int> Head)
- {
- if (Head == null)
- return false; // no leaves and no parent.
- if (IsLeaf(Head))
- return false; // head is a leaf, so there is no parent.
- var right = Head.GetRight();
- var left = Head.GetLeft();
- if (left != null)
- {
- if (left.GetValue() < Head.GetValue())
- return true;
- else if (!IsRightSmallANDLeftBig(left))
- return false;
- }
- if (right != null)
- {
- if (right.GetValue() > Head.GetValue())
- return true;
- else if (!IsRightSmallANDLeftBig(right))
- return false;
- }
- return true;
- }
- public static bool IsRightSmallANDLeftBig(BinNode<int> Head)
- {
- if (Head == null)
- return false; // no leaves and no parent ~null~.
- var right = Head.GetRight();
- var left = Head.GetLeft();
- if (left == null && right == null)
- return false;
- if (left == null && right != null)
- return IsRightSmallANDLeftBig(right);
- if (left != null && right == null)
- return IsRightSmallANDLeftBig(left);
- if (left != null && right != null)
- {
- if (left.GetValue() > Head.GetValue() && right.GetValue() < Head.GetValue())
- {
- return IsRightSmallANDLeftBig(left) && IsRightSmallANDLeftBig(right);
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement