当前位置:网站首页>C # realizes the first order traversal, middle order traversal and second order traversal of binary tree
C # realizes the first order traversal, middle order traversal and second order traversal of binary tree
2022-06-29 12:53:00 【Dusk and starry sky】
In this paper, C# The implementation of binary tree traversal 、 In the sequence traversal 、 After the sequence traversal
1、 The first sequence traversal
///
/// The first sequence traversal
///
///
static void PreOrder(BiTNode T) {
if (T!=null) {
visit(T);
PreOrder(T.lchild);
PreOrder(T.rchild);
}
2、 In the sequence traversal
///
/// In the sequence traversal
///
///
static void InOrder(BiTNode T)
{
if (T != null)
{
InOrder(T.lchild);
visit(T);
InOrder(T.rchild);
}
}
3、 After the sequence traversal
///
/// After the sequence traversal
///
///
static void PostOrder(BiTNode T)
{
if (T != null)
{
PostOrder(T.lchild);
PostOrder(T.rchild);
visit(T);
}
}
4、 Node access
///
/// Output of node value
///
static void visit(BiTNode T) {
Console.Write(T.data+" ");
}
The test of main Function as follows
public const int MaxSize = 50;
static void Main(string[] args)
{
BiTNode T = new BiTNode() ;
int x=0;
// Create a binary tree
T.data = 1;
T.lchild= new BiTNode();
T.lchild.data = 2;
T.rchild = new BiTNode();
T.rchild.data = 3;
T.lchild.rchild=new BiTNode();
T.lchild.rchild.data = 4;
T.lchild.rchild.lchild= new BiTNode();
T.lchild.rchild.lchild.data = 6;
T.rchild.rchild = new BiTNode();
T.rchild.rchild.data = 5;
Console.WriteLine(“ The value of traversal first :”);
PreOrder(T);
Console.WriteLine();
Console.WriteLine(“ The value of middle order traversal :”);
InOrder(T);
Console.WriteLine();
Console.WriteLine(“ The value of post order traversal :”);
PostOrder(T);
Console.WriteLine();
Console.WriteLine(“ The value of an ordered traversal in non recursion :”);
InOrder2(T);
Console.WriteLine();
Console.WriteLine(“ Value of hierarchy traversal :”);
LevelOrder(T);
Console.ReadLine();
}
边栏推荐
- qt 自定义控件 :取值范围
- Recommended model recurrence (I): familiar with torch rechub framework and use
- cmake 报错
- Gbase8s database sorts standard or raw result tables
- 1. Opencv实现简单颜色识别
- QQ集体被盗号,猝不及防的大型社死名场面
- Viewing splitchunks code segmentation from MPX resource construction optimization
- 深入理解 volatile 关键字
- Cereal mall project
- [comprehensive case] credit card virtual transaction identification
猜你喜欢

JVM之方法区

QQ group was stolen, a large-scale social death scene caught off guard

1. opencv realizes simple color recognition

go 学习-搭建开发环境vscode开发环境golang

Matlab简单入门

倍福PLC通过CANOpen通信控制伺服

C # clue binary tree through middle order traversal

AES-128-CBC-Pkcs7Padding加密PHP实例

How to create new user for ORACLE 19c (CDB & PDB)

Uncover the practice of Baidu intelligent test in the field of automatic test execution
随机推荐
Problem solving: modulenotfounderror: no module named 'pip‘
【智能QbD风险评估工具】上海道宁为您带来LeanQbD介绍、试用、教程
InDesign插件-常规功能开发-JS调试器打开和关闭-js脚本开发-ID插件
MFC dialog program core -isdialogmessage function -msg message structure -getmessage function -dispatchmessage function
【综合案例】信用卡虚拟交易识别
面试突击61:说一下MySQL事务隔离级别?
nvtmpp
倍福PLC通过CANOpen通信控制伺服
Gbase 8s extended external connection 1
NvtBack
Murphy safety was selected for signing 24 key projects of Zhongguancun Science City
Proteus软件初学笔记
go 学习-搭建开发环境vscode开发环境golang
nacos启动报错
Recommended model reproduction (II): fine arrangement model deepfm, DIN
Go Senior Engineer required course | I sincerely suggest you listen to it. Don't miss it~
Recurrence of recommended models (III): recall models youtubednn and DSSM
Method area of JVM
Pygame 精准检测图像碰撞
1. opencv realizes simple color recognition