Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void IsBst()
- {
- if (Root == null)
- {
- Console.WriteLine("Empty tree");
- return;
- }
- @h@bool isbst = true;
- IsBstHelper2(Root, ref isbst);
- if (isbst == true)
- {
- Console.WriteLine("This a Binary Search Tree");
- }
- else
- Console.WriteLine("This is not a Binary Search Tree");
- }
- private void IsBstHelper2(Node node, ref bool isBst)
- {
- if (node == null)
- return;
- if (node.Left != null)
- IsBstHelper2(node.Left, ref isBst);
- if (node.Right != null)
- IsBstHelper2(node.Right, ref isBst);
- if (node.Right != null && node.Right.Data < node.Data)
- isBst = false;
- if (node.Left != null && node.Left.Data < node.Data)
- isBst = false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement