c语言树,插入没问题,遍历出问题了,求大佬帮帮忙

Gnglas 2020-01-23 11:31:00



额,总而言之,我自己都看不懂,嘿嘿,这个代码不行的话,大佬推荐点别的思路也好,
我就是想用递归插入,可能中间不知到咋了



/*************************************************************************
> File Name: tow_the_tree.c
> Author: Gnglas
> Mail: 2254228017@qq.com
> Created Time: 2020年01月23日 星期四 10时18分39秒
************************************************************************/
#include<stdio.h>
#include<stdlib.h>
typedef struct Node
{
int nuber;
struct Node *lChild,*rChild;
}NewTree;
void TopTree(NewTree *root)
{
int Nuber;
NewTree *new = NULL;
root =(NewTree *) malloc(sizeof(NewTree));
if(root == NULL) exit(1);
scanf("%d",&Nuber);
if(new != NULL)
{
if(Nuber <new->nuber)
TopTree(root->lChild);
if(Nuber > new->nuber)
TopTree(root->rChild);

}
if(new == NULL ) new = root;
root->nuber = Nuber;
if(Nuber == 0)
{
root = NULL;
}
if(root != NULL)
TopTree(root);
}
void main()
{
NewTree *root;
TopTree(root);
PushTree(root);
}
void PushTree(NewTree *root)
{
PushTree(root->lChild);
printf("%dn",root->nuber);
PushTree(root->rChild);
}
//嘿嘿,内啥,真的麻烦大佬了

...全文
247 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Gnglas 2020-01-23
  • 打赏
  • 举报
回复
求大佬详解,我小白一枚

3,881

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
  • 其它技术问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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