这是一个创建二叉树的程序 麻烦大家帮我改一下错误,最好把关键处标出来 谢谢

天地一棵树 2009-03-30 05:23:52
#include <stdio.h>
#include <conio.h>
#include <malloc.h>
typedef char TelmType;
typedef struct node //定义一个结构体
{
TelemType date;
struct node *lc,*rc;
}Bitree Node
Bitree Node*create_bt()
{
Bitree Node *root =(Bitree Node*)malloc(sizeof(Bitree Node)); //分配存储空间
Bitree Node *p,s[20];
TelemType Node x;
int i,j;
printf("i,x");
scanf("%d,%c",&i,&x);
while(i!=0&&x!='#')
{
p=(Bitree Node *)malloc(sizeof(Bitree Node));
p=date=x;
p->lc=NULL;
p->rc=NULL;
s[i]=p;
if(i==1)
{
root=p;
}
else
{j=i/2;
if(i%2==0)
s[j]->lc=p;
else s[j]->rc=p;
printf("i,x");
scanf("%d,%c",&i,&x);
}
return root;
}
void main()
{
Bitree Node *bt;
bt=create_br();
getchar();
}
...全文
64 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xidianxiancai 2009-03-31
  • 打赏
  • 举报
回复
#include <stdio.h>
#include <conio.h>
#include <malloc.h>
typedef char TelmType;
typedef struct node //定义一个结构体
{
TelmType date;
struct node *lc,*rc;
}Node;

Node *create_bt(void)
{
Node *root =(Node *)malloc(sizeof(Node)); //分配存储空间
Node *p,**s;
s = (Node **)malloc(sizeof(Node)*20);
TelmType x;
int i,j;
printf("i,x");
scanf("%d,%c",&i,&x);
getchar();
while (i!=0 && x!='#')
{
p=(Node *)malloc(sizeof(Node));
p->date = x;
p->lc = NULL;
p->rc = NULL;
s[i] = p;
if (i==1)
{
root=p;
}
else
{
j=i/2;
if (i%2==0)
s[j]->lc=p;
else
s[j]->rc=p;
printf("i,x");
scanf("%d,%c",&i,&x);
}
}
return root;
}

int main(void)
{
Node *bt;
bt = create_bt();
return 0;
}
qq675927952 2009-03-30
  • 打赏
  • 举报
回复
呵呵,up 一下1L
jn989 2009-03-30
  • 打赏
  • 举报
回复
1楼辛苦了,lz以后要仔细的呀,问题解决了,飘过……呵呵
wuyanchao 2009-03-30
  • 打赏
  • 举报
回复
发现1楼对于指针问题特别感兴趣 ,每次一有这个类型 就出现
cyy20121120 2009-03-30
  • 打赏
  • 举报
回复

typedef struct _AVLNODE
{
struct _AVLNODE *pLeft;
struct _AVLNODE *pRight;
int m_nValue;
}AVLNODE,*pAVLNODE;

void InsertNode(pAVLNODE pNode, int nParam)
{
pAVLNODE pHead = pNode;

/* create a avlnode. */
AVLNODE *s = (AVLNODE*) malloc(sizeof(AVLNODE));
if (!s)
{
printf("malloc failed!\n");
return;
}

s->m_nValue = nParam;
s->pLeft = NULL;
s->pRight = NULL;

/* Create a root node. */
if (!pHead)
{
pHead = s;
pNode = pHead;
return;
}

/* when the value less than middle value, put it in the right node.*/
while (pHead)
{
if (pHead->m_nValue < nParam)
{
if (!pHead->pRight)
{
pHead->pRight = s;
pNode = pHead;
return;
}
else
{
pHead = pHead->pRight;
continue;
}
}
else
{
if (!pHead->pLeft)
{
pHead->pLeft = s;
pNode = pHead;
return ;
}
else
{
pHead = pHead->pLeft;
continue;
}
}
}
}
  • 打赏
  • 举报
回复
帮你改了不下10处错别字,。代码肯定不是你写的

typedef char TelmType;
typedef struct node //定义一个结构体
{
TelmType date; //都是错别字
struct node *lc,*rc;
}Bitree; //这里少;

Bitree *create_bt()
{
Bitree *root =(Bitree *)malloc(sizeof(Bitree)); //分配存储空间
Bitree *p,*s[20]; //s[i]应该是指针,照你后面的用法
TelmType x;
int i,j;
printf("i,x");
scanf("%d,%c",&i,&x);
while(i!=0&&x!='#')
{
p=(Bitree *)malloc(sizeof(Bitree));
p->date=x; //p=data=x;全是错别字
p->lc=NULL;
p->rc=NULL;
s[i]=p; //p是指针
if(i==1)
{
root=p;
}
else
{
j=i/2;
if(i%2==0)
s[j]->lc=p;
else s[j]->rc=p;
printf("i,x");
scanf("%d,%c",&i,&x);
}
}
return root;
}

void main()
{
Bitree *bt;
bt=create_bt();
}

69,374

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧