model_server/api/src/GenericTree.cxx
// FUNCTION:
//
//     GenericTree::InsertChild
//
// DESCRIPTION:
//
//     Insert the specified node at the specified index. Indices
//     begin at zero. To insert at the end of the list, use an
//     index of -1.
//
// INPUTS:
//
//     newChild    The new child to insert.
//     index       The position at which the new child should appear.




Insert the specified node at the specified index. Indices
begin at zero. To insert at the end of the list, use an
index of -1.



newChild    The new child to insert.
index       The position at which the new child should appear.
Insert the specified node at the specified index . Indices begin at zero . To insert at the end of the list use an index of - 1 . newChild The new child to insert . index The position at which the new child should appear .
GenericTree *GenericTree::InsertChild(GenericTree *newChild, int index)
{
  newChild->parent = this;
  GenericTree *prev = NULL;
  GenericTree *next = firstChild;
  while ((index != 0) && (next != NULL))
  {
    prev = next;
    next = next->nextSibling;
    --index;
  }
  if (prev != NULL) {
    prev->nextSibling = newChild;
    newChild->prevSibling = prev;
  } else {
    firstChild = newChild;
  }
  if (next != NULL) {
    next->prevSibling = newChild;
    newChild->nextSibling = next;
  }
  newChild->nextSibling = next;
  newChild->prevSibling = prev;
  return newChild;
}
GenericTree * GenericTree :: InsertChild ( GenericTree * newChild , int index ) { newChild -> parent = this ; GenericTree * prev = NULL ; GenericTree * next = firstChild ; while ( ( index != 0 ) && ( next != NULL ) ) { prev = next ; next = next -> nextSibling ; -- index ; } if ( prev != NULL ) { prev -> nextSibling = newChild ; newChild -> prevSibling = prev ; } else { firstChild = newChild ; } if ( next != NULL ) { next -> prevSibling = newChild ; newChild -> nextSibling = next ; } newChild -> nextSibling = next ; newChild -> prevSibling = prev ; return newChild ; }
FUNCTION:
GenericTree::InsertChild
FUNCTION : GenericTree :: InsertChild