Code Fragment: AVLTree2



  void rebalance(BTPosition& z) {			// rebalancing utility
    while (!T.isRoot(z)) {				// rebalance up to root
      z = T.parent(z);
      setHeight(z);					// compute new height
      if (!isBalanced(z)) {				// restructuring needed
        BTPosition x = tallGrandchild(z);
        z = T.restructure(x);				// trinode restructure
        setHeight(T.leftChild(z));			// update heights
        setHeight(T.rightChild(z));
        setHeight(z);
      }
    }
  }