数据结构 二叉树的线索存储
来源:互联网 发布:mac os 分辨率设置 编辑:程序博客网 时间:2024/05/21 07:04
#include <stdio.h>#include <stdlib.h>#include <iostream.h>#define OK 1#define ERROR 0#define OVERFLOW -2typedef char TElemType;typedef enum {Link,Thread} PointerTag;typedef struct BiThrNode{TElemType data;struct BiThrNode *lchild,*rchild;PointerTag LTag;PointerTag RTag;}BiThrNode, *BiThrTree;BiThrTree pre;void Create_BiThrTree(BiThrTree &T){TElemType ch;cin >> ch;if (ch == '#'){T = NULL;}else{T = (BiThrTree)malloc(sizeof(BiThrNode));if (!T){exit(OVERFLOW);}T->data = ch;Create_BiThrTree(T->lchild);if (T->lchild){T->LTag = Link;}Create_BiThrTree(T->rchild);if (T->rchild){T->RTag = Link;}}}void InThreading(BiThrTree p){if (p){InThreading(p->lchild);if (!p->lchild){p->LTag = Thread;p->lchild = pre;}if (!pre->rchild){pre->RTag = Thread;pre->rchild = p;}pre = p;InThreading(p->rchild);}}int InOrderThreading(BiThrTree &Thrt, BiThrTree T){if (!(Thrt = (BiThrTree)malloc(sizeof(BiThrNode)))){exit(OVERFLOW);}Thrt->LTag = Link;Thrt->RTag = Thread;Thrt->rchild = Thrt;if (!T){Thrt->lchild = Thrt;}else{Thrt->lchild = T;pre = Thrt;InThreading(T);pre->rchild = Thrt;pre->RTag = Thread;Thrt->rchild = pre;}return OK;}int InOrderTraverse_Thr(BiThrTree T){BiThrTree p;p = T->lchild;while (p != T){while (p->LTag == Link){p = p->lchild;}printf("%c",p->data);while (p->RTag == Thread && p->rchild != T){p = p->rchild;printf("%c",p->data);}p = p->rchild ;}return OK;}int main(){BiThrTree T,H;Create_BiThrTree(T);InOrderThreading(H,T);InOrderTraverse_Thr(T);printf("\n");return 0;}
0 0
- 数据结构 二叉树的线索存储
- 二叉树的二叉线索存储表示
- 数据结构-->线索二叉树
- 数据结构--线索二叉树
- 【数据结构】线索二叉树
- 数据结构-线索二叉树
- 数据结构 - 线索二叉树
- 线索二叉树-数据结构
- 【数据结构】线索二叉树
- 数据结构-线索二叉树
- 数据结构--线索二叉树
- 数据结构---线索二叉树
- 数据结构---线索二叉树
- 数据结构--线索二叉树
- [数据结构]线索二叉树
- 二叉树的链式存储与线索二叉树-数据结构(14)
- 数据结构之二叉树的线索化
- 线索二叉树的遍历(数据结构)
- 字符串哈希算法
- 程序员必知(四):找次品
- 汇编程序的多模块化
- 合泰 HT66F30 定时器初始化
- inux 学习书目推荐
- 数据结构 二叉树的线索存储
- 面积
- java类中打印信息乱码?
- 第16周项目2-指来指去(2)
- 邮票问题
- 表达式求值
- Selenium-Webdriver(python) (九) --- 操作对象
- 【Java并发编程】之十三:生产者—消费者模型(含代码)
- UISlider控件的使用解析