#include #include #include #define MAX_TREE_SIZE 100 typedef struct { int data; int parent; //双亲位置域 }PTNode; /*双亲表示法树结构*/ typedef struct { PTNode node[MAX_TREE_SIZE]; int count; //根的位置和节点个数 }PTree; /*树的孩子兄弟表示结点结构定义*/ typedef struct node{ int data; struct node *firstchild; struct node *rightsib; }BTNode,*BTree; void init_ptree(PTree *tree) { tree->count=-1; } //初始化树结点(孩子兄弟表示法) BTNode GetTreeNode(int x) { BTNode t; t.data=x; t.firstchild=t.rightsib=NULL; return t; } //树的前序遍历(递归) void preorder(BTNode *T) { if(T!=NULL) { printf("%d ",T->data); preorder(T->firstchild); preorder(T->rightsib); } } //树的前序遍历(非递归) void preorder2(PTree T) { int i; for(i=0;ifirstchild); printf("%d ",T->data); inoeder(T->rightsib); } } //树后序遍历(非递归) void inoeder2(PTree T) { int i; for(i=T.count-1;i>=0;i--) { printf("%d ",T.node[i]); } } //层次遍历 void level(PTree T) { int i; for(i=0;irightsib,level+1); for(i=1;i<=8*level;i++) printf(" "); printf("-------%d\n",root->data); PrintBTree(root->firstchild,level+1); } } //输出树 void print_ptree(PTree tree) { int i; printf(" 序号 结点 双亲\n"); for(i=0;i<=tree.count;i++) { printf("%8d%8d%8d",i,tree.node[i].data,tree.node[i].parent); printf("\n"); } } /*用双亲表示法创建树*/ PTree CreatTree(PTree T) { int i=1; int fa,ch; PTNode p; for(i=1;ch!=-1;i++) { printf("输入第%d 结点:\n",i); scanf("%d,%d",&fa,&ch); printf("\n"); p.data=ch; p.parent=fa; T.count++; T.node[T.count].data = p.data; T.node[T.count].parent = p.p...