本文介绍了代表树的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 C#(或 .net)中是否有任何对象表示二叉树(或出于好奇)和 n 叉树?
Are there any objects in C# (or in .net) that represents a binary tree (or for curiosity) and n-ary tree?
我不是在谈论表示树控件,而是作为模型对象.
I am not talking about presentation tree controls, but as model objects.
如果没有,有没有好的外部实现?
If not, are there any good external implementations?
推荐答案
NGenerics 项目是一个很棒的数据结构和算法集合,包括二叉树.
The NGenerics project is a awesome collection of data structures and algorithms including a 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; }
// ...
}
这篇关于代表树的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!