protected void buildLeavesMiddleOut(BallNode node) throws Exception {
  if (node.m_Left != null && node.m_Right != null) {
    buildLeavesMiddleOut(node.m_Left);
    buildLeavesMiddleOut(node.m_Right);
  }
 else   if (node.m_Left != null || node.m_Right != null) {
    throw new Exception("Invalid leaf assignment. Please check code");
  }
 else {
    BallNode n2=buildTreeMiddleOut(node.m_Start,node.m_End);
    if (n2.m_Left != null && n2.m_Right != null) {
      node.m_Left=n2.m_Left;
      node.m_Right=n2.m_Right;
      buildLeavesMiddleOut(node);
    }
 else     if (n2.m_Left != null || n2.m_Right != null) {
      throw new Exception("Invalid leaf assignment. Please check code");
    }
  }
}

protected void buildLeavesMiddleOut ( BallNode node ) throws Exception { if ( node . m_Left != null && node . m_Right != null ) { buildLeavesMiddleOut ( node . m_Left ) ; buildLeavesMiddleOut ( node . m_Right ) ; } else if ( node . m_Left != null || node . m_Right != null ) { throw new Exception ( "Invalid leaf assignment. Please check code" ) ; } else { BallNode n2 = buildTreeMiddleOut ( node . m_Start , node . m_End ) ; if ( n2 . m_Left != null && n2 . m_Right != null ) { node . m_Left = n2 . m_Left ; node . m_Right = n2 . m_Right ; buildLeavesMiddleOut ( node ) ; } else if ( n2 . m_Left != null || n2 . m_Right != null ) { throw new Exception ( "Invalid leaf assignment. Please check code" ) ; } } }
applies the middle out build procedure to the leaves of the tree . the leaf nodes should be the ones that were created by createanchorshierarchy ( ) . the process continues recursively for the leaves created for each leaf of the given tree until for some leaf node < = m_maxinstancesinleaf instances remain in the leaf .
