以下程序26 处错误!
//*信管031 ***数据结构作业*//
//*建立二叉树并求深度*//
#include<malloc.h>
#include<string.h>
#include<stdio.h>
int commend,ord;
void ctree()
{
struct tnode{int val,order;
int depth;
struct tnode *lchild,*rchild,*parent;}
struct tnode *p,*q,*rt;
printf("输入命令字符,1左,2右,3退出");
scanf("%d",&commend);
if(commend!=1&&commend!=2&&commend!=3)
{printf("order out of switch!");
break;}
switch(commend){
case 1:while(p->lchild)p=p->lchild;
rt=(tnode *)malloc(sizeof(tnode));
rt->parent=p;
rt->order=q->order+1;
printf("输入新结点的值:");
scanf("%d",&rt->val);
rt->depth=p->depth+1;
p->lchild=rt;
q=rt;
ctree();
break;
case 2:while(p->rchild)p=p->rchild;
rt=(tnode *)malloc(sizeof(tnode));
rt->parent=p;
rt->order=q->order+1;
printf("输入新结点的值:");
scanf("%d",&rt->val);
rt->depth=p->depth+1;
p->rchild=rt;
q=rt;
ctree();
break;
case 3:break;
}
vis(struct tnode *pos){if(pos->depth>ord)
ord=pos->depth;
printf("现在最大结点序号为:%d/n深度为:%d"pos->order,ord);
printf("该结点的值为:%d",pos->val);
}
tran(struct tnode *base){base=root;
if(base->lchild)
{base=base->lchild;
tran(base);}
vis(root);
if(base->rchild){
base=base->rchild;
tran(base);}
}
main(){int ord;
struct tnode *q,*rt,*root;
root=rt=(tnode *)malloc(sizeof(tnode));
rt->depth=1;
rt->order=1;
printf("输入第一个结点的值:");
scanf("%d",&rt->val);
p=q=rt;
void ctree();
printf("进入遍历并求深度过程!");
tran(root);
}