二叉树递归遍历问题

来源:百度知道 编辑:UC知道 时间:2024/06/05 19:51:37
为什么我的二叉树递归遍历出的结果都是错误的,请高手指教!能运行,但遍历结果是错的,比如先序输入二叉树(abd..e..c..)中序递归遍历结果应该为(dbeca)才对,但现在程序遍历结果却是(bdeca),下面后序递归遍历结果同样出错,请高手给看看是怎么会事啊??

#include <stdio.h>
#include <stdlib.h>
//#include <conio.h>
#define max 100
struct TREE //二叉树结点结构
{
char data;//数据
int flag;//标志量,若为0表示结点没有被访问过,若为1表示已经被访问过
struct TREE *lsubtree;//左孩子
struct TREE *Rsubtree; //右孩子
};

struct TREE *tree;

void createtree(struct TREE *&p) //先序创建二叉树~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{
char ch;
ch = getchar();
if (ch == '\n')
{
printf("没有生成二叉树\n");
exit(1);
}
else if(ch == '.')
{
//printf("空树\n");
p = NULL;
}
else
{
p = (struct TREE*)malloc(sizeof(struct TREE));//分配结点空间
p->data = ch;
p->flag=0;//设标志量为0
createtree(p-

http://www.pudn.com/downloads115/sourcecode/math/detail483785.html
BiTree 实现二叉树的基本功能,创建,先序、中序、后序、层序遍历,查找双亲和孩子节点,插入删除节点,功能很完善;