当前位置:网站首页>C#通过中序遍历对二叉树进行线索化
C#通过中序遍历对二叉树进行线索化
2022-06-29 12:05:00 【黄昏和星空】
本文讲解
C#通过中序遍历对二叉树进行线索化
在二叉树的结点上加上线索的二叉树称为线索二叉树,对二叉树以某种遍历方式(如先序、中序、后序或层次等)进行遍历,使其变为线索二叉树的过程称为对二叉树进行线索化。 [1]
对于n个结点的二叉树,在二叉链存储结构中有n+1个空链域,利用这些空链域存放在某种遍历次序下该结点的前驱结点和后继结点的指针,这些指针称为线索,加上线索的二叉树称为线索二叉树。
这种加上了线索的二叉链表称为线索链表,相应的二叉树称为线索二叉树(Threaded BinaryTree)。根据线索性质的不同,线索二叉树可分为前序线索二叉树、中序线索二叉树和后序线索二叉树三种。
注意:线索链表解决了无法直接找到该结点在某种遍历序列中的前驱和后继结点的问题,解决了二叉链表找左、右孩子困难的问题。
///
/// 通过中序遍历对二叉树线索化
///
///
///
static void InThread(ref ThreadNode p, ref ThreadNode pre)
{
if (p != null)
{
InThread(ref p.lchild,ref pre);
if (p.lchild == null) { p.lchild = pre; p.ltag = 1; }
if (pre!=null&&pre.rchild==null) { pre.rchild = p;pre.rtag = 1; }
pre = p;
InThread(ref p.rchild, ref pre);
}
}
///
/// 创建线索二叉树主逻辑
///
///
static void CreateInThread(ref ThreadNode T) {
ThreadNode pre = null;
if (T!=null) {
InThread(ref T,ref pre);
pre.rchild = null;
pre.rtag = 1;
}
边栏推荐
- Inferiority complex and transcendence the meaning of life to you
- [cloud native] 2.4 kubernetes core practice (middle)
- 地球观测卫星数据
- 测试--自动化测试:关于unittest框架
- MIT linear algebra Chinese Notes
- LeetCode_ Double pointer_ Medium_ 328. parity linked list
- ERP编制物料清单 基础
- 二十三、1-Bit数据的存储(延迟线/磁芯/DRAM/SRAM/磁带/磁盘/光盘/Flash SSD)
- huffman编码
- 23、 1-bit data storage (delay line / core /dram/sram/ tape / disk / optical disc /flash SSD)
猜你喜欢

【JUC系列】同步工具类之ThreadLocal

【LeetCode】14、最长公共前缀

Artbench: the first class balanced, high-quality, clean annotated and standardized artwork generation data set

Principle and process of MySQL master-slave replication

How can colleges and universities build future oriented smart campus based on cloud native? Full stack cloud native architecture vs traditional IT architecture

《高难度谈话》突破谈话瓶颈,实现完美沟通

推荐模型复现(二):精排模型DeepFM、DIN

高校如何基于云原生构建面向未来的智慧校园?全栈云原生架构VS传统IT架构

Go Senior Engineer required course | I sincerely suggest you listen to it. Don't miss it~

How to create new user for ORACLE 19c (CDB & PDB)
随机推荐
Gbase8s database select has order by Clause 6
23、 1-bit data storage (delay line / core /dram/sram/ tape / disk / optical disc /flash SSD)
Kyligence Zen, an intelligent indicator driven management and decision-making platform, is newly launched and is in limited internal testing
Gbase8s database for read only clause
DALL-E 2背后的工程实践:确保模型的输出符合内容政策
Gbase8s database into temp clause creates a temporary table to save query results.
ZALSM_EXCEL_TO_INTERNAL_TABLE 导入数据大问题解决
Do you think people who learn machinery are terrible?
墨菲安全入选中关村科学城24个重点项目签约
Syntax of gbase8s database incompatible with for update clause
求大数的阶乘 ← C语言
Recurrence of recommended models (III): recall models youtubednn and DSSM
揭秘百度智能测试在测试自动执行领域实践
Gbase8s database select has order by Clause 6
【LeetCode】14、最长公共前缀
模糊图片变清晰,一键双色图片,快速整理本地图片...这8个在线图片工具申请加入你的收藏夹!
MySQL master-slave synchronous asynchronous replication semi synchronous replication full synchronous replication
huffman编码
Gbase8s database into external clause
oracle 19c : change the user sys/system username pasword under Linux