void PrintSubTree(FILE *OutFile, TreeNode Node, int Indent) { int i,itsrank,itslocation; itsrank = Rank(Node); fprintf(OutFile, "[%5d] ", Node); for (i=1; i <= Indent; i++) fprintf(OutFile,". "); Write_String(OutFile, NodeName(Node)); fprintf(OutFile ,"(%1d)", itsrank); itslocation = SourceLocation(Node); if(itslocation!=UndefinedString) { fprintf (OutFile, " @ "); Write_String(OutFile, itslocation); } if (Decoration(Node) != 0) fprintf(OutFile, " Decoration: %1d", Decoration(Node)); fprintf(OutFile,"\n"); for (i=1; i <= itsrank; i++) PrintSubTree (OutFile, Child(Node, i), Indent+1); }
int main(void) { Menu menu; BinNode *root; root = NULL; do { BinNode x; switch (menu = SelectMenu()) { case Insert :x = Read("Insert"); root = ApndNode(root,&x);break; case Search: x = Read("Search"); SrchNode(root,&x); break; case Print: puts("----------------"); PrintTree(root); break; case PrintSub: x = Read("Insert"); puts("----------------"); PrintSubTree(root, &x); break; } } while (menu != Term); FreeTree(root); return(0); }
/* 部分木を表示する */ void PrintSubTree(BinNode *p, BinNode *w) { int cond; if (p == NULL) { printf("%s is not registered\n",w->name); } else { if((cond = strcmp(w->name,p->name))==0) { PrintTree(p); } else { if (cond < 0){ PrintSubTree(p->left, w); } else{ PrintSubTree(p->right, w); } } } }
void PrintTree(FILE *OutFile, TreeNode Node) { PrintSubTree(OutFile, Node, 0); }