手机
当前位置:查字典教程网 >编程开发 >C#教程 >C#二叉搜索树插入算法实例分析
C#二叉搜索树插入算法实例分析
摘要:本文实例讲述了C#二叉搜索树插入算法。分享给大家供大家参考。具体实现方法如下:publicclassBinaryTreeNode{publi...

本文实例讲述了C#二叉搜索树插入算法。分享给大家供大家参考。具体实现方法如下:

public class BinaryTreeNode { public BinaryTreeNode Left { get; set; } public BinaryTreeNode Right { get; set; } public int Data { get; set; } public BinaryTreeNode(int data) { this.Data = data; } } public void InsertIntoBST(BinaryTreeNode root, int data) { BinaryTreeNode _newNode = new BinaryTreeNode(data); BinaryTreeNode _current = root; BinaryTreeNode _previous = _current; while (_current != null) { if (data < _current.Data) { _previous = _current; _current = _current.Left; } else if (data > _current.Data) { _previous = _current; _current = _current.Right; } } if (data < _previous.Data) _previous.Left = _newNode; else _previous.Right = _newNode; }

希望本文所述对大家的C#程序设计有所帮助。

【C#二叉搜索树插入算法实例分析】相关文章:

浅谈二叉查找树的集合总结分析

c#启动EXE文件的方法实例

C# 获取枚举值的简单实例

c#实现sunday算法实例

C# zxing二维码写入的实例代码

基于C#委托的深入分析

C#反射在实际应用中的实例代码

C#排序算法之快速排序

C#实现写入与读出文本文件的实例代码

C#几种获取网页源文件代码的实例

精品推荐
分类导航