树的孩子链表存储结构

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 树的孩子链表存储结构 { public class Node<T> { private T value; private ChildNode firstNode; public T Value { get { return this.value; } set { this.value = value; } } public ChildNode FirstNode { get { return this.firstNode; } set { this.firstNode = value; } } public Node() { this.value = default(T); this.firstNode = null; } public Node(T t, ChildNode node) { this.value = t; this.firstNode = node; } } public class ChildNode { private int index; private ChildNode nextNode; public int Index { get { return this.index; } set { this.index = value; } } public ChildNode NextNode { get { return this.nextNode; } set { this.nextNode = value; } } public ChildNode() { this.index = -1; this.nextNode = null; } public ChildNode(int i,ChildNode next) { this.index = i; this.nextNode = next; } public ChildNode(int i) { this.index = i; this.nextNode = null; } } public class TreeDS<T> { private Node<T>[] nodesInTree; public Node<T>[] NodesInTree { get { return this.nodesInTree; } set { this.nodesInTree = value; } } public TreeDS() { this.nodesInTree = new Node<T>[10];//默认带10个节点 } public TreeDS(int n) { this.nodesInTree = new Node<T>[n]; } //返回某结点的子节点 public List<Node<T>> GetChildNodes(Node<T> n) { List<Node<T>> list = new List<Node<T>>(); if (n.FirstNode != null) { ChildNode cn = n.FirstNode; Node<T> node = this.nodesInTree[cn.Index]; list.Add(node); cn = cn.NextNode; while (cn != null) { list.Add(this.nodesInTree[cn.Index]); cn = cn.NextNode; } return list; } else { return list; } } } }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值