typedef struct BitTNode{
datatype data;
struct BiTNode *lchild;*rchild;
} BiTNode,*BiTree;
void CreateBinTree(BinTree *T)
{/*以加入结点的先序序列输入,构造二叉链表*/
char *ch;
scanf("\n%c",&ch);
if(ch=='0')
*T=NULL;
else { *T=(BinTNode *)malloc(sizeof(BinTNode));
(*T)->data=ch;
CreatBinTree(&(*T)->lchild);
CreatBinTree(&(*T)->rchild);
}
}
void InOrderOut(BinTree T)
{/*中序遍历输出二叉树T的结点值*/
if(T)
{InOrderOut(T->lchild);
printf("%3c",T->data);
InOrderOut(T->rchild);
}
void PreOrderOut(BiTree T)
{/*先序遍历输出二叉树T的结点值*/
printf("%3c",T->data);
PreOrderOut(T->lchild);
PreOrderOut(T->rchild);
}
void PostOrderOut(BiTree T)
{ /*后序遍历输出二叉树T的结点值*/
PostOrderOut(T->lchild);
PostOrderOut(T->rchild);
printf("%3c",T->data);
}
int Countleaf(BiTree T)
{ /*开始时,T为根结点所在链结点的指针,返回值为T的叶子数*/
if(T==NULL) return(0);
if(T->lchild==NULL&&T->rchild==NULL) retur(1);
printf(Countleaf(T->rchild)+Counleaf(T->rchild));
}
main()
{BtTree bt;
CreateBinTree(&bt);
InOrderOut(bt);
PostOrderOut(bt);
PreOrderOut(bt);
Countleaf(bt);}
唉, 懒了, 不想写了, 就这些吧, 其它的你加吧..
[此贴子已经被作者于2005-5-15 22:37:02编辑过]