国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#二叉搜索樹插入算法實例分析

2020-01-24 01:54:39
字體:
來源:轉載
供稿:網(wǎng)友

本文實例講述了C#二叉搜索樹插入算法。分享給大家供大家參考。具體實現(xiàn)方法如下:

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#程序設計有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 广宗县| 海丰县| 若羌县| 柞水县| 库尔勒市| 辽阳市| 赤峰市| 嘉禾县| 凉山| 徐汇区| 莱州市| 四川省| 吉首市| 始兴县| 许昌县| 诏安县| 车险| 吐鲁番市| 札达县| 高尔夫| 静海县| 青冈县| 于都县| 望都县| 安远县| 井研县| 嵩明县| 察隅县| 忻城县| 嵊州市| 灌南县| 惠东县| 宝兴县| 黔江区| 三明市| 长白| 新民市| 咸宁市| 墨竹工卡县| 玉林市| 余江县|