void DisposeNodes(Node *node) { Node *curr; for (curr = node->firstChild; curr; curr = curr->nextSibling) { DisposeNodes(curr); } DisposeNode(node); }
void UnrootRTree(TTree *tree) /* Used to unroot a rooted tree */ { TNode *P, *Q, *R, *newRoot; double len, len2; if (!tree->rooted || tree->numTips<3) return; P=tree->tips[0]; Q=P->branch0; newRoot=Q; while (Q!=tree->root) { R=Q->branch0; len=Q->length0; if (Q->branch1==P) { len2=Q->length1; Q->branch1=R; Q->length1=len; } else { len2=Q->length2; Q->branch2=R; Q->length2=len; } Q->branch0=P; Q->length0=len2; P=Q; Q=R; } len=R->length1+R->length2; if (R->branch1==P) Q=R->branch2; else Q=R->branch1; Q->branch0=P; Q->length0=len; if (P->branch1==R) { P->branch1=Q; P->length1=len; } else { P->branch2=Q; P->length2=len; } tree->root=newRoot; DisposeNode(R); tree->rooted=0; }
/*----------*/ void DisposeTreeNodes(TTree *tree) { TNode *P, *O; if ( tree ) { P=tree->nodeList; while (P!=NULL) { O=P; P=P->next; DisposeNode(O); } tree->nodeList=NULL; } } /* DisposeTreeNodes */