二叉树的实现:
public class Node{ T date; public T Date { get { return date; } set { date = value; } } Node lChild; public Node LChild { get { return lChild; } set { lChild = value; } } Node rChild; public Node RChild { get { return rChild; } set { rChild = value; } } public Node(T value) { date = value; lChild = null; rChild = null; } public Node() { date = default(T); lChild = null; rChild = null; } public Node(Node lc, Node rc) { date = default(T); lChild = lc; rChild = rc; } } public class BinaryTree { Node head; public Node Head { get { return head; } set { head = value; } } public BinaryTree() { head = null; } public bool IsEmpty() { if (head == null) { return true; } else { return false; } } public Node GetLeftChild(Node p) { if (p != null) { return p.LChild; } else { return null; } } public Node GetRightChild(Node p) { if (p != null) { return p.RChild; } else { return null; } } public BinaryTree(T value) { Node root = new Node (value); head = root; } public void InsertL(T value, Node p) { Node newNode = new Node (value); newNode.LChild = p.LChild; p.LChild = newNode; } public void InsertR(T value, Node p) { Node newNode = new Node (value); newNode.RChild = p.RChild; p.RChild = newNode; } public Node DeleteLeftChild(Node p) { if (p == null) { return null; } Node temp = null; if (p != null && p.LChild != null) { temp = p.LChild; } p.LChild = null; return temp; } public Node DeleteRightChild(Node p) { if (p == null) { return null; } Node temp = null; if (p != null && p.RChild != null) { temp = p.RChild; } p.RChild = null; return temp; } public bool IsLeftNode(Node p) { if (p != null && p.LChild == null && p.RChild == null) { return true; } return false; } }