我在没懂的后面加注释 希望大家指教
#include<stdio.h>
#include<stdlib.h>
#define MAXSIZE 100
typedef struct binode
{
char data;
struct binode *lchild;
struct binode *rchild;
}Binode;
Binode* create()
{
char ch;
Binode *t;
scanf("%c",&ch);
if(ch=='\n ')
{
t=(Binode *)malloc(sizeof(Binode));
t->data=ch;
t->lchild=create();
t->rchild=create();
}
return t;
}
char putcharacter(char ch) //问题1:这个地方是用来输入数据的吧,是怎么做到的?
{
return(putchar(ch));
}d
void Preorder(Binode * t,char(* visit)(char ch)) //问题二:这个定义我一点也没有明白,visit根本没有
定义这个函数,怎么就直接用了?它是怎么实现的。
后面的(char ch)是什么意思?
//问题3:如何+一个程序,实现求二叉树的高度
{
void PrintElement(char e)
{
printf("%c",e);
return;
}
if(t){
visit(t->data);
Preorder(t->lchild,visit);
Preorder(t->rchild,visit);
}
}
void Inorder(Binode *t,char(* visit)(char ch))
{
if(t){
Inorder(t->lchild,visit);
visit(t->data);
Inorder(t->rchild,visit);
}
}
void Postorder(Binode *t,char(* visit)(char ch))
{
if(t){
Postorder(t->lchild,visit);
Postorder(t->rchild,visit);
visit(t->data);
}
}
main()
{
char ch;
Binode *t=0;
Binode *create();
char putcharacter(char ch);
void Preorder(Binode * t,char(* visit)(char ch));
void Inorder(Binode *t,char(* visit)(char ch));
void Postorder(Binode *t,char(* visit)(char ch));
printf("\nto create bintree...\n\n");
t=create();
printf("Preorder visit bintree:\n");
Preorder(t,putcharacter);
printf("\n");
printf("Inorder visit bintree:\n");
Inorder(t,putcharacter);
printf("\n");
printf("Postorder visit bintree:\n");
Postorder(t,putcharacter);
}