首页 > 电脑/网络 >程序设计 >C/C++
2017-11-16 00:00:00 2017-11-17 23:59:59 http://h.chanjet.com/activity/hkj/xlaw/xlaw.html http://yyk.iask.sina.com.cn/pic/fimg/3991231702_800.jpg 2018-03-26 00:00:00 2018-04-25 23:59:59

程序报错:二叉树的创建和输出

递归先序建立二叉树,然后非递归中序遍历输出。在完成creatBiTree的输入后程序报错自动关闭,麻烦各位帮找下原因? #include<stdio.h> #include<stdlib.h> #define NULL 0 #define OK 1 #define MAXSIZE 20 typedef struct BiNode { int data; struct BiNode *lchild,*rchild; }BiNode,*BiTree; BiTree creatBiTree(BiTree T) { int elem; printf("Input the elem of Tree:"); scanf("%d",&elem); if(elem==-1) { T=NULL; return(T); } else { T=(BiTree)malloc(sizeof(BiNode)); T->data=elem; creatBiTree(T->lchild); creatBiTree(T->rchild); return(T); } } void printBiTree(BiTree T) { BiTree stack[MAXSIZE],p; int top=0; p=T; while(p!=NULL||top>0) { if(p!=NULL) { stack[++top]=p; p=p->lchild; } else { p=stack[top--]; printf(" %d",p->data); p=p->rchild; } } } void main() { BiTree T=NULL; T=creatBiTree(T); printf("The struct of BiTree:"); printBiTree(T); } [展开]

谢*** 2012-05-13 18:59:55 举报

好评回答

其他回答

50分钟前 广告
查看详情

类似问题换一批

相关知识 换一批

C语言的学习教材跟所用软...

入门:清华大学出版社,谭浩强的c语言程序设计 可以用turbo c,环...

热度TOP 查看更多

大家都关注换一批

提问

热点搜索更多

举报

举报原因(必选):

取消 确定举报
3a7f7956b2984ca88f5d5c19c0fe4715