看不明白!
//建立二叉树(按前序方法)
void buildbt(btree &T)
{
char ch;
ch=getchar();
if(ch == ' ')
T=NULL;
else
{
T=(btree)malloc(sizeof(btnode));
T->data=ch;
buildbt(T->lchild);
buildbt(T->rchild);
}
}
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
typedef struct node
{
char data;
struct node *left,*right;
}node;
node *bitree;
void creat(bitree)
{
char ch;
scanf("%c",&ch);
if(ch==' '){bitree=NULL;}
T=(BitNode *)malloc(sizeof(BitNode ));
T->data=ch;
creat(bitree->left);
creat(bitree->right);
}
void inorder(node *)
{
if(t!=NULL)
{
inorder(t->left);
printf("%c",t->data);
inorder(t->right);
}
}
void main()
{
node *t;
creat(t);
inorder(t);
}
哪位高手能不能帮我看看 谢谢了
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#define NULL 0
typedef struct node
{
char data;
struct node *left,*right;
}node,*bitree;
void creat(bitree T)
{
char ch;
scanf("%c",&ch);
if(ch==' '){T=NULL;}
T=(node *)malloc(sizeof(node));
T->data=ch;
creat(T->left);
creat(T->right);
}
void inorder(bitree t)
{
if(t!=NULL)
{
inorder(t->left);
printf("%c",t->data);
inorder(t->right);
}
}
void main()
{
node *t;
creat(t);
inorder(t);
}
请问9楼
我把你的word改成char型后为什么遍不过去啊
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
typedef struct BinTree
{
char word;
struct BinTree *LSubTree;
struct BinTree *RSubTree;
}Node;
Node* CreateTree()
{
Node *tree;
char v;
printf("输入一个数字来建树: (空格等于空)\n");
scanf("%c",&v);
if( v=='#')
tree=NULL;
else
{
tree=(Node*)malloc(sizeof(Node));
tree->word= v;
tree->LSubTree=CreateTree();
tree->RSubTree=CreateTree();
}
return tree;
}
void Inorder(Node *tree)
{
if(tree!= NULL)
{
Inorder(tree->LSubTree);
printf("%3d\n", tree->word);
Inorder(tree->RSubTree);
}
}
void main()
{
Node *Stree;
Stree= CreateTree();
Inorder(Stree);
}
[此贴子已经被作者于2006-5-8 22:41:03编辑过]