帮我看一下非递归遍历二叉数的算法

hanzq 2004-05-07 08:04:47
struct btnode
{ char data;
struct btnode * lchild;
struct btonde * rchild;
};
struct node
{ struct btnode *addr;
struct node *link;
};
inorder(root)
struct btnode * root;
{
struct node *top,*p;
top=NULL;
while(root!=NULL||top!=NULL)
{
while(root!=NULL)
{
struct node * p=(struct node *)malloc(sizeof(struct node));
p->addr=root;
p->link=top;
top=p;
root=root->lchild;
}
if(top!=NULL)
{
root=top->addr;
printf("%c",root->data);
p=top;
top=top->link;
free(p);
root=root->rchild;
}
}return;
}
这段代码编译出错 :“undefimed structure 'btonde' in function inorder”
其他没有语法错误

怎么改?
...全文
90 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
hewittlee 2004-05-08
  • 打赏
  • 举报
回复
struct btonde * rchild; //小心点
junnyfeng 2004-05-07
  • 打赏
  • 举报
回复
struct btnode
{ char data;
struct btnode * lchild;
struct btonde * rchild; //这里btnode写错了
};
后面的最好也检查一下
cngdzhang 2004-05-07
  • 打赏
  • 举报
回复

#include <stdio.h>
#include <stdlib.h>

struct btnode
{ char data;
struct btnode * lchild;
struct btnode * rchild;
};
struct node
{ struct btnode *addr;
struct node *link;
};

void inorder(struct btnode *root)
{
struct node *top,*p;
top=NULL;
while(root!=NULL||top!=NULL)
{
while(root!=NULL)
{
struct node * p=(struct node *)malloc(sizeof(struct node));
p->addr=root;
p->link=top;
top=p;
root=root->lchild;
}
if(top!=NULL)
{
root=top->addr;
printf("%c",root->data);
p=top;
top=top->link;
free(p);
root=root->rchild;
}
}return;
}

void main()
{
}
zhouqingyuan 2004-05-07
  • 打赏
  • 举报
回复
自己看编译信息!!!
freefalcon 2004-05-07
  • 打赏
  • 举报
回复
粗心,写错了

struct btnode
{ char data;
struct btnode * lchild;
struct btnode * rchild; //btnode
};

69,371

社区成员

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

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