#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#define OK 1
#define ERROR 0
using namespace std;
enum PointerTag {Link, Thread}; //声明枚举,Link == 0:指针,Thread == 1:线索
typedef char TElemType;
typedef int Status;
typedef struct BiThrNode {
TElemType data;
struct BiThrNode *lchild, *rchild; //左右孩子指针
PointerTag LTag, RTag; //左右标志
}BiThrNode, *BiThrTree;
BiThrTree pre; //全局变量
Status CreateBiTree(BiThrTree &T) { //以先序次序创建二叉树
char ch;
cin >> ch;
if (ch == '#') T = NULL;
else {
T = (BiThrNode *)malloc(sizeof(BiThrNode)); //申请空间
T->data = ch; //结点
T->LTag = Link; //初始化结点,其lchild域全部有左孩子
CreateBiTree(T->lchild); //左孩子
CreateBiTree(T->rchild); //右孩子
}
return OK;
}
/*
所有线索化的实质:将二
C语言实现中序线索化二叉树并遍历
最新推荐文章于 2024-04-29 19:53:30 发布