Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.99 KB | None | 0 0
  1.         public void IsBst()
  2.         {
  3.             if (Root == null)
  4.             {
  5.                 Console.WriteLine("Empty tree");
  6.                 return;
  7.             }
  8.  
  9.             @h@bool isbst = true;
  10.             IsBstHelper2(Root, ref isbst);
  11.             if (isbst == true)
  12.             {
  13.                 Console.WriteLine("This a Binary Search Tree");
  14.             }
  15.             else
  16.                 Console.WriteLine("This is not a Binary Search Tree");
  17.         }
  18.  
  19.         private void IsBstHelper2(Node node, ref bool isBst)
  20.         {
  21.             if (node == null)
  22.                 return;
  23.             if (node.Left != null)
  24.                 IsBstHelper2(node.Left, ref isBst);
  25.             if (node.Right != null)
  26.                 IsBstHelper2(node.Right, ref isBst);
  27.             if (node.Right != null && node.Right.Data < node.Data)
  28.                     isBst = false;
  29.             if (node.Left != null && node.Left.Data < node.Data)
  30.                     isBst = false;
  31.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement