急,请大家帮忙看看一个创建二叉树的程序

来源:百度知道 编辑:UC知道 时间:2024/05/30 06:08:42
void createbintree(bintree *t){
printf("创建树:\n");
char ch;
if((ch=getchar())==' ') t=NULL;
else{
t=(bintree*)malloc(sizeof(bintree));
t->data=ch;
createbintree(t->lchild);
createbintree(t->rchild);
}
}
应该说,执行这个程序的时候,按下回车键后二叉树创建过程就结束了,程序应该执行后面的代码,但为什么我运行的时候到这里是个死循环,按回车出不来,到底是哪里出问题了???很着急,请帮忙看下,在线等,一旦问题解决立即采纳!
谢谢你,但是*t=NULL; *t=(bintree*)malloc(sizeof(bintree));
类型不配啊。
#include "stdio.h"
#include "malloc.h"
typedef struct bintree{
char data;
struct bintree* lchild;
struct bintree* rchild;
}bintree;

typedef struct strack{
bintree* data[100];
int top;
}seqstack;
void push(seqstack* s,bintree *t){

s->data[++s->top]=t;
}
/////////////////////////

void createbintree(bintree *t){
printf("创建树:\n"); //这句最好不要
char ch;
if((ch=getchar())==' ') *t=NULL;
else{
*t=(bintree*)malloc(sizeof(bintree));
(*t)->data=ch;
createbintree(&(*t)->lchild);
createbintree(&(*t)->rchild);
}
}
传值是单向的,传址则要操作地址。

==============================
*t=(bintree*)malloc(sizeof(binnode));

要不,贴贴你的定义。

==============================
#include "stdio.h"
#include "malloc.h"
typedef struct node{
char data;
struct node *lchild,* rchild;
}*bintree;

void createbintree(bintree *t)
{
char ch;
if((ch=getchar())==' ') *t=NULL;
else{
*t=(bintree*)malloc(sizeof(bintree));
(*t)->data=ch;
createbintree(&(*t)->lchild);
createbintree(&(*t)->rchild);
}
}

===============================
晕,关键是,在创建