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; } } } }