树的孩子兄弟存储结构

本文介绍了一种树的数据结构表示方法——孩子兄弟表示法,并提供了两种实现方式:一种不包含父节点属性,查找父节点较困难;另一种增加了父节点属性,便于查找父节点。同时还给出了树类的基本定义。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 树的孩子兄弟存储结构 { //无父母结点属性,查找父母结点较为困难 public class CSNode<T> { private T value; private CSNode<T> firstChildNode; private CSNode<T> nextSiblingNode; public T Value { get { return this.value; } set { this.value = value; } } public CSNode<T> FirstChildNode { get { return this.firstChildNode; } set { this.firstChildNode = value; } } public CSNode<T> NextSiblingNode { get { return this.nextSiblingNode; } set { this.nextSiblingNode = value; } } public CSNode() { this.value = default(T); this.firstChildNode = null; this.nextSiblingNode = null; } public CSNode(T t) { this.value = t; } public CSNode(T t,CSNode<T> firstChild) { this.value = t; this.firstChildNode = firstChild; } public CSNode(T t, CSNode<T> firstChild,CSNode<T> nextSibling) { this.value = t; this.firstChildNode = firstChild; this.nextSiblingNode = nextSibling; } } //有父母结点属性,增设父母结点属性,查找父母结点更加方便 public class CSNodeWithParent<T> { private T value; private CSNodeWithParent<T> parentNode; private CSNodeWithParent<T> firstChildNode; private CSNodeWithParent<T> nextSiblingNode; public T Value { get { return this.value; } set { this.value = value; } } public CSNodeWithParent<T> ParentNode { get { return this.parentNode; } set { this.parentNode = value; } } public CSNodeWithParent<T> FirstChildNode { get { return this.firstChildNode; } set { this.firstChildNode = value; } } public CSNodeWithParent<T> NextSiblingNode { get { return this.nextSiblingNode; } set { this.nextSiblingNode = value; } } public CSNodeWithParent() { this.value = default(T); this.firstChildNode = null; this.nextSiblingNode = null; } public CSNodeWithParent(T t) { this.value = t; } public CSNodeWithParent(T t, CSNodeWithParent<T> firstChild) { this.value = t; this.firstChildNode = firstChild; } public CSNodeWithParent(T t, CSNodeWithParent<T> firstChild, CSNodeWithParent<T> nextSibling) { this.value = t; this.firstChildNode = firstChild; this.nextSiblingNode = nextSibling; } public CSNodeWithParent(T t, CSNodeWithParent<T> firstChild, CSNodeWithParent<T> nextSibling,CSNodeWithParent<T> parent) { this.value = t; this.ParentNode = parent; this.firstChildNode = firstChild; this.nextSiblingNode = nextSibling; } } //树类 public class CSTree<T> { private CSNode<T> head; public CSNode<T> Head { get { return this.head; } set { this.head = value; } } } }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值