1 typedef struct btnode *btlink;//二叉树结点结构定义
2 struct btnode
3 {
4 int data; //储存结点标号
5 btlink left; //指向左子树的指针
6 btlink right; //指向右子树的指针
7 }Btnode;
8
9 btlink NewBNode() //创建一个新的树的结点
10 {
11 btlink p;
12 if(p=malloc(sizeof(Btnode))==0)
13 Error("Exhausted memory.");
14 else
15 return p;
16 }
17
18 typedef struct binarytree *BinaryTree;//root是指向树根的指针
19 typedef struct binarytree
20 {
21 btlink root;
22 }BTree;
23
24 BinaryTree BinaryInit() //Binary将root置为空指针
25 {
26 BinaryTree T=malloc(sizeof*T);
27 T->root=0;
28 return T;
29 }
30
31 int BinaryEmpty()//检测T的根结点root是否为空指针
32 {
33 return T->root==0;
34 }
35
36 int Root(BinaryTree T)//返回根节点的标号
37 {
38 if(BinaryEmpty(T))
39 Error("Tree is Empty.");
40 return
41 T->root->data;
42 }