void balance(
    int           kFactor,
    NodeStack     stack,
    GBSNode       fpoint,
    int           fpidx,
    int           maxBal)
  {
    /* Get parent of balance point           */
    GBSNode bparent = stack.node(fpidx - 1);

    switch (kFactor)
    {
      case 2:
        balance2(stack, bparent, fpoint, fpidx, maxBal);
        break;
      case 4:
        balance4(stack, bparent, fpoint, fpidx, maxBal);
        break;
      case 6:
        balance6(stack, bparent, fpoint, fpidx, maxBal);
        break;
      case 8:
        balance8(stack, bparent, fpoint, fpidx, maxBal);
        break;
      case 12:
        balance12(stack, bparent, fpoint, fpidx, maxBal);
        break;
      case 16:
        balance16(stack, bparent, fpoint, fpidx, maxBal);
        break;
      case 24:
        balance24(stack, bparent, fpoint, fpidx, maxBal);
        break;
      case 32:
        balance32(stack, bparent, fpoint, fpidx, maxBal);
        break;
      default:
        String x =
         "Unknown K factor in fringe balance: " + kFactor;
        error(x);
        break;
    }
  }
void balance ( int kFactor , NodeStack stack , GBSNode fpoint , int fpidx , int maxBal ) { GBSNode bparent = stack . node ( fpidx - 1 ) ; switch ( kFactor ) { case 2 : balance2 ( stack , bparent , fpoint , fpidx , maxBal ) ; break ; case 4 : balance4 ( stack , bparent , fpoint , fpidx , maxBal ) ; break ; case 6 : balance6 ( stack , bparent , fpoint , fpidx , maxBal ) ; break ; case 8 : balance8 ( stack , bparent , fpoint , fpidx , maxBal ) ; break ; case 12 : balance12 ( stack , bparent , fpoint , fpidx , maxBal ) ; break ; case 16 : balance16 ( stack , bparent , fpoint , fpidx , maxBal ) ; break ; case 24 : balance24 ( stack , bparent , fpoint , fpidx , maxBal ) ; break ; case 32 : balance32 ( stack , bparent , fpoint , fpidx , maxBal ) ; break ; default : String x = "Unknown K factor in fringe balance: " + kFactor ; error ( x ) ; break ; } }
Balance a fringe following the addition of its final node.

@param kFactor The K factor for the tree.
@param stack The stack of nodes through which the insert operation
passed.
@param fpoint The fringe balance point (the top of the fringe).
@param fpidx The index within the stack of fpoint
@param maxBal Maximum allowed fringe imbalance.  This is derived
from the K factor but has to be computed by the
caller anyway so it is passed along here.