这段时间一直在复习数据结构,把做的练习贴出来,就当是留下的脚印吧
线索二叉树,就好像是给排列在不同地方的对象用一根无形的绳子穿起来了,变成了“线形”的,这样每个结点的前驱和后继就能直接得到或者容易找到了。
线索化的过程需要用到遍历算法,一旦线索建立后,在此结构上遍历就可以不用递归、也不用栈了,实现更加容易了。
线索化的过程需要用到遍历算法,一旦线索建立后,在此结构上遍历就可以不用递归、也不用栈了,实现更加容易了。
头文件BitTree.h
#ifndef BITTREE_H
#define BITTREE_H
#define OK 1
#define ERROR 0
#define TRUE 1
#define FALSE 0
typedef enum{Link,Thread} PointTag;
typedef char Element;
typedef int Status;
typedef struct Node{
Element data;
struct Node* left; //指向左孩子
struct Node* right; //指向右孩子
PointTag Ltag; //左右标志
PointTag Rtag;
}BitNode,*BitTree;
Status visit(Element e);
Status CreateTree(BitTree &T);
void InThreading(BitTree T);
void InOrderThreading(BitTree &H,BitTree T);
Status InOrderTraverse_Thr(BitTree L);
#endif //BITTREE_H
实现文件BitTree.cpp
#include "BitTree.h"