Objects that represent trees

前端 未结 4 1893
暖寄归人
暖寄归人 2020-12-05 07:41

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 m

4条回答
  •  悲&欢浪女
    2020-12-05 07:58

    The NGenerics project is a awesome collection of data structures and algorithms including a Binary Tree.

    public class BinaryTree : IVisitableCollection, ITree
    {
      // Methods
      public void Add(BinaryTree subtree);
      public virtual void breadthFirstTraversal(IVisitor visitor);
      public virtual void 
             DepthFirstTraversal(OrderedVisitor orderedVisitor);
      public BinaryTree GetChild(int index);
      public bool Remove(BinaryTree 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 this[int i] { get; }
      public virtual BinaryTree Left { get; set; }
      public virtual BinaryTree Right { get; set; }
    
      // ...
    }
    

提交回复
热议问题