c# - 代表树的对象

标签 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/

相关文章:

c# - 如何从 c# 返回列表并通过 com 在 vc++ 中使用它

.net - 为什么 Visual Studio 2005 Debug模式不起作用?

datetime - VB6 中的 CDate 与 VB.NET 版本有何不同?

algorithm - 查找由数组表示的 2 BST 是否同构

c# - 数据库设计 Entity Framework 中的导航属性

c# - 如何在 Windows 8 风格应用程序中将对象从一个框架传递到另一个框架

css - 在 Ajax 更新的 div 中显示 CSS 图像

c++ - 需要帮助来理解错误消息

c# - SqlDataReader 不存在数据时尝试读取无效

.net - 为自定义类型创建 ADO.NET 映射