解题思路:
注意事项:
参考代码:
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
typedef struct tree{
char data;
struct tree *Lchlid,*Rchlid;
}tree;
tree *root;
tree* build_tree(tree *root){
char ch;
scanf("%c",&ch);
if (ch ==' ') {
root=NULL;
}
else{
root=(tree *)malloc(sizeof(tree));
root->data=ch;
root->Lchlid=build_tree(root->Lchlid);
root->Rchlid=build_tree(root->Rchlid);
}
return root;
}
void preprint(tree *root){
if(root==NULL)
return;
else{
printf("%c ",root->data);
preprint(root->Lchlid);
preprint(root->Rchlid);
}
}
void inprint(tree *root){
if(root==NULL) return;
else{
inprint(root->Lchlid);
printf("%c ",root->data);
inprint(root->Rchlid);
}
}
void postprint(tree *root){
if(root==NULL)
return;
else{
postprint(root->Lchlid);
postprint(root->Rchlid);
printf("%c ",root->data);
}
}
int main (){
tree *root;
root=build_tree(root);
preprint(root);
printf("\n");
inprint(root);
printf("\n");
postprint(root);
return 0;
}
0.0分
0 人评分
点我有惊喜!你懂得!浏览:1987 |
C语言程序设计教程(第三版)课后习题6.10 (C语言代码)浏览:709 |
校门外的树 (C语言代码)浏览:1122 |
C语言程序设计教程(第三版)课后习题5.8 (C语言代码)浏览:943 |
模拟计算器 (C语言代码)浏览:891 |
分糖果 (C++代码)浏览:1447 |
母牛的故事 (C语言代码)浏览:435 |
C语言程序设计教程(第三版)课后习题6.4 (C语言代码)浏览:744 |
C语言程序设计教程(第三版)课后习题11.8 (C语言代码)浏览:880 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:542 |