title: How to determine if Binary Tree is BST
body: <p>I am trying to figure out a logic to determine if Binary Tree is BST. I want to use the inorder approach and I don't want to use an extra array to store all incoming values as we know that Inorder should be in sorted order. I want to check the incoming value w/o having to store it in an array. Below is my attempt which is not working.</p>
  
  <pre><code>   public bool CheckBST(BstNode root)
          {
              BstNode prev = new BstNode(Int32.MinValue);
              if (root == null)
                  return true;
              if (root.left != null)
              {
                  return CheckBST(root.left);
              }
              if (prev != null &amp;&amp; prev.data &gt;= root.data) // means data  is not sorted hence NOT   BST
                  return false;
              prev = root;
              if(root.right!=null)
              {
                  return CheckBST(root.right);
              }
              return true;
          }
  </code></pre>