<分区>
C#(或 .net)中是否有表示二叉树(或出于好奇)和 n 叉树的对象?
我不是在谈论表示树控件,而是作为模型对象。
如果没有,有什么好的外部实现吗?
标签 c# .net tree binary-tree
<分区>
C#(或 .net)中是否有表示二叉树(或出于好奇)和 n 叉树的对象?
我不是在谈论表示树控件,而是作为模型对象。
如果没有,有什么好的外部实现吗?
最佳答案
NGenerics项目是一个很棒的数据结构和算法集合,包括 Binary Tree .
public class BinaryTree<T> : IVisitableCollection<T>, ITree<T>
{
// Methods
public void Add(BinaryTree<T> subtree);
public virtual void breadthFirstTraversal(IVisitor<T> visitor);
public virtual void
DepthFirstTraversal(OrderedVisitor<T> orderedVisitor);
public BinaryTree<T> GetChild(int index);
public bool Remove(BinaryTree<T> child);
public virtual void RemoveLeft();
public virtual void RemoveRight();
// ...
// Properties
public virtual T Data { get; set; }
public int Degree { get; }
public virtual int Height { get; }
public virtual bool IsLeafNode { get; }
public BinaryTree<T> this[int i] { get; }
public virtual BinaryTree<T> Left { get; set; }
public virtual BinaryTree<T> Right { get; set; }
// ...
}
关于c# - 代表树的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1806511/