#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