Tree (directed acyclic graph) implementation

前端 未结 4 1959
忘掉有多难
忘掉有多难 2020-12-14 22:22

I require a tree / directed acyclic graph implementation something like this:

public class TreeNode {
    private K key; // \'key\' for this node         


        
4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-14 23:21

    There doesn't seem to be anything of the kind. I asked a similar question last week and ended up implementing my own tree. My implementation was very similar to what you're proposing:

    public class TreeNode
    {
        private LinkedList> children = new LinkedList>();
        public T value { get; set; }
    
        public TreeNode(T value)
        {
            this.value = value;
        }
        public LinkedList> GetChildren()
        {
            return children;
        }
    }
    

    You will have to add a link back to the parent(s).

提交回复
热议问题