title: What is the correct implementation of AVL Tree Rotation?
body: <p>When inserting 50,49,48 into an AVL Tree, it prints out.</p>
  
  <pre><code>The root is: 50 
  50 Level: 0 Height: 0
  
   49 Level: 1 Height: 0
  50 Level: 0 Height: -1
  
  50 Level: 0 Height: 0 --&gt;&gt; Rotation did not work?
  </code></pre>
  
  <p>Here are my functions.
  Rotate Left:</p>
  
  <pre><code>void AVLTree::rotateLeft(AVLNode* node)
  {   
      AVLNode* otherNode = node;
  
  
      otherNode = node-&gt;leftchild;
      node-&gt;leftchild = otherNode-&gt;rightchild;
      otherNode-&gt;rightchild = node;
  
      node-&gt;height = max( height(node-&gt;leftchild), height(node-&gt;rightchild)) +1;
      otherNode-&gt;height = max( height(otherNode-&gt;leftchild) , height(otherNode-&gt;rightchild))+1;
      node = otherNode;
  
  }
  </code></pre>
  
  <p>insert:</p>
  
  <pre><code>AVLTree::AVLNode* AVLTree::insert(int d,AVLNode *n){
  if (n == NULL)
  {
      n = new AVLNode;
      n-&gt;data = d;
      n-&gt;leftchild = NULL;
      n-&gt;rightchild = NULL;
      n-&gt;height = 0;
  
  } else if( d &lt; n-&gt;data) {
  
      n-&gt;leftchild = insert(d,n-&gt;leftchild);
  
      if (height(n-&gt;leftchild) - height(n-&gt;rightchild) == 2) {
          if (d &lt; n-&gt;leftchild-&gt;data) {
              rotateLeft(n);
          } else {
              rotateLeftTwice(n);
          }
      }
  
  } else if (d &gt; n-&gt;data) {
  
      n-&gt;rightchild = insert(d,n-&gt;rightchild);
  
      if (height(n-&gt;rightchild) - height(n-&gt;leftchild) == 2) {
          if (d &gt; n-&gt;rightchild-&gt;data) {
              rotateRight(n);
          } else {
              rotateRightTwice(n);
          }
      }
  } else {    
      ;
  }
  n-&gt;height = max(height(n-&gt;leftchild), height(n-&gt;rightchild))+1;
  return n;}
  </code></pre>