C#二叉搜刮樹拔出算法實例剖析。本站提示廣大學習愛好者:(C#二叉搜刮樹拔出算法實例剖析)文章只能為提供參考,不一定能成為您想要的結果。以下是C#二叉搜刮樹拔出算法實例剖析正文
本文實例講述了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#法式設計有所贊助。