title: how to follow a recursive isBST function?
body: <p>I'm trying to follow a specific implementation of a recursive (in-order traversal) isBST function.</p>
  
  <p>I tried to simulate it with the simple invalid BST example:
  root=5, root.left=3, root.left.right=8</p>
  
  <pre><code>  5
   /
  3
   \
    8
  </code></pre>
  
  <p>i'm getting either 'true' or 'false' but without having to check the last node '8'.
  the code is as follows:</p>
  
  <pre><code>/* wrapper that keeps track of the previous value */
  class PrevWrapper {
      int data = Integer.MIN_VALUE;
  }
  
  boolean isBST(Node root, PrevWrapper prev) {
      /* base case: we reached null*/
      if (root == null) {
          return true;
      }
  
      if(!isBST(root.left, prev)) {
          return false;
      }
  
      /* If previous in-order node's data is larger than
       * current node's data, BST property is violated */
      if (prev.data &gt; root.data) {
          return false;
      }
  
      /* set the previous in-order data to the current node's data*/
      prev.data = root.data;
  
      return isBST(root.right, prev);
  }
  
  boolean isBST(Node root) {
      return isBST(root, new PrevWrapper());
  }
  </code></pre>
  
  <p>what is the correct order of returning the recursive calls?</p>
  
  <p><strong>EDIT</strong>:</p>
  
  <p>I was thinking:
  (#)isBST(5,min), isBST(3,min), isBST(3.left=null,min) - returns true, skips to prev=3, isBST(8,3), isBST(8.left=null,3) - returns true, skips to prev=8, isBST(8.right=null,8) - returns true to (#), <strong>checks 8 > 5? returns false</strong>.</p>
  
  <p>I think I got it, is this the correct order of calls?
  thanks in advance.</p>