作者在 2008-07-19 11:37:05 发布以下内容
#include"stdio.h"
#include"conio.h"
#include"alloc.h"
typedef struct btree
{
char data;
struct btree *left;
struct btree *right;
}
btnode ,*Btree;
Btree Root;
void init()
{
Root=NULL;
}
void creat(Btree *bt)
{
char ch;
ch=getchar();
if(ch=='.')*bt=NULL;
else
{
*bt=(Btree)malloc(sizeof(btnode));
(*bt)->data=ch;
creat(&((*bt)->left));
creat(&((*bt)->right));
}
}
void visit(char b)
{
printf(" %c",b);
}
void inorder(Btree root)
{
if(root!=NULL)
{
inorder(root->left);
visit(root->data);
inorder(root->right);
}
}
main()
{
Btree root,p;
int i;
clrscr();
init();
root=Root;
creat(Root);
inorder(root);
printf("\n");
#include"conio.h"
#include"alloc.h"
typedef struct btree
{
char data;
struct btree *left;
struct btree *right;
}
btnode ,*Btree;
Btree Root;
void init()
{
Root=NULL;
}
void creat(Btree *bt)
{
char ch;
ch=getchar();
if(ch=='.')*bt=NULL;
else
{
*bt=(Btree)malloc(sizeof(btnode));
(*bt)->data=ch;
creat(&((*bt)->left));
creat(&((*bt)->right));
}
}
void visit(char b)
{
printf(" %c",b);
}
void inorder(Btree root)
{
if(root!=NULL)
{
inorder(root->left);
visit(root->data);
inorder(root->right);
}
}
main()
{
Btree root,p;
int i;
clrscr();
init();
root=Root;
creat(Root);
inorder(root);
printf("\n");
}
对数据结构不甚了解,写了个中序遍历,我输入ab.df..g..c.e.h.. 可是出不来结果,请各位高手看一下,帮小弟弄正确