C语言第六章作业及上机.doc

作业3: 这个作业也是上机实验题 试编写程序: (1) 建立下面这样一棵二叉树 (2) 后序遍历这棵二叉树 (3) 按层次遍历 (4) 求叶子数和深度。 (5) 查找値为‘H’的结点,如存在,则打印出’H’的所有祖先。 #includestdio.h #includemalloc.h #define max 100 typedef struct bnode { char data; struct bnode *lchild,*rchild; }Bnode,*Btree; typedef struct { Btree data[max]; int front ; int rear; }queue; char a[]={#,A,B,C,D,#,E,F,#,G,#,#,H,#}; int length=14; Btree Creatree() { char ch; Btree S; ch=getchar(); if(ch==#) { S=NULL; } else { S=(Btree)malloc(sizeof(Bnode)); S-data=ch; S-lchild=Creatree(); S-rchild=Creatree(); } return S; } void Lastree(Btree S) /*后续遍历*/ { if(S) {

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档