title: Why is my code for checking if a BST tree is AVL wrong?
body: <p>Hi I wrote this code that checks if a given BST is AVL or not, and in my mind it works but in the test it doesn't. 
  The structure is a classic BST, with an integer, left and right.</p>
  
  <pre><code>bool AbsoluteDifference(int a, int b)
  {
  return ((a-b) &lt;= 1)) ||(b-a) &lt;= 1)); 
  } 
  
   void aux_avl (BST b , int &amp;l_var, bool &amp;isAVL)
  {
  if (b == NULL)
    l_var--;  
    //In consecuence of not asking if the left or right is NULL or not
    //when I make the recursive call, if it is I have to decrease the value
  else if (isAVL == true)//I don't want to keep checking if I already know that it's not AVL
  
  {
  
     int l_left = l_var + 1;
     aux_avl(b-&gt;left,l_left,isAVL);
  
     int l_right = l_var +1;
     aux_avl(b-&gt;right, l_right,isAVL); 
  
     isAVL = AbsoluteDifference(l_left,l_right);
  
     lvar = max(l_left,l_right);
  }
  }
  
  bool is_AVL(BST b)
  {
     if (b == NULL)
        return true;
     else
    {
       int l_var =0;
       bool isAVL = true;
       auxavl(b,l_var,isAVL);
  
       return isAVL;
    }
  }
  </code></pre>