请问这个C语言程序是干嘛的(什么意思) 怎么才能运行
#include<malloc.h>#include<stdio.h>typedefstructnode{chardata;structnode*lchild,*rchi...
#include <malloc.h>
#include <stdio.h>
typedef struct node
{ char data;
struct node *lchild,*rchild;
}JD;
void preorder(JD *bt)
{ if(bt!=NULL)
{ printf("%c ",bt->data);
preorder(bt->lchild);
preorder(bt->rchild);
}
}
void inorder(JD *bt)
{ if(bt!=NULL)
{ inorder(bt->lchild);
printf("%c ",bt->data);
inorder(bt->rchild);
}
}
void postorder(JD *bt)
{ if(bt!=NULL)
{ postorder(bt->lchild);
postorder(bt->rchild);
printf("%c ",bt->data);
}
}
JD *crt_bt_pre(JD *bt)
{ char ch;
printf("ch=");
scanf("%c",&ch);
getchar();
if(ch==' ') bt=NULL;
else
{ bt=(JD *)malloc(sizeof(JD));
bt->data=ch;
bt->lchild=crt_bt_pre(bt->lchild);
bt->rchild=crt_bt_pre(bt->rchild);
}
return(bt);
}
void main()
{ JD *head=NULL;
/*char a[]={'A','B','C',' ',' ','D','E',' ','G',' ',' ','F',' ',' ',' '};*/
head=crt_bt_pre(head);
preorder(head);
printf("\n");
inorder(head);
printf("\n");
postorder(head);
printf("\n");
} 展开
#include <stdio.h>
typedef struct node
{ char data;
struct node *lchild,*rchild;
}JD;
void preorder(JD *bt)
{ if(bt!=NULL)
{ printf("%c ",bt->data);
preorder(bt->lchild);
preorder(bt->rchild);
}
}
void inorder(JD *bt)
{ if(bt!=NULL)
{ inorder(bt->lchild);
printf("%c ",bt->data);
inorder(bt->rchild);
}
}
void postorder(JD *bt)
{ if(bt!=NULL)
{ postorder(bt->lchild);
postorder(bt->rchild);
printf("%c ",bt->data);
}
}
JD *crt_bt_pre(JD *bt)
{ char ch;
printf("ch=");
scanf("%c",&ch);
getchar();
if(ch==' ') bt=NULL;
else
{ bt=(JD *)malloc(sizeof(JD));
bt->data=ch;
bt->lchild=crt_bt_pre(bt->lchild);
bt->rchild=crt_bt_pre(bt->rchild);
}
return(bt);
}
void main()
{ JD *head=NULL;
/*char a[]={'A','B','C',' ',' ','D','E',' ','G',' ',' ','F',' ',' ',' '};*/
head=crt_bt_pre(head);
preorder(head);
printf("\n");
inorder(head);
printf("\n");
postorder(head);
printf("\n");
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询