/// <summary> /// Returns a tree /// A /// / \ /// B C /// / \ / \ /// D E F G /// /// </summary> /// <returns></returns> static Tree BuildTree() { var tree = new Tree(); var node = new Node("A", new Node("B", "D", "E"), new Node("C", "F", "G")); tree.Root = node; return tree; }
public void DFSPostorder(Node n, Action<Node> visit) { if (n == null) return; DFSPostorder(n.Left, visit); DFSPostorder(n.Right, visit); visit(n); }
public void Invert(Node n) { if (n == null) return; var temp = n.Right; n.Right = n.Left; n.Left = temp; Invert(n.Left); Invert(n.Right); }
public Node(string value, Node leftVal = null, Node rightVal = null) { this.Value = value; this.Left = leftVal; this.Right = rightVal; }
public Node(string value, string leftVal = null, string rightVal = null) { this.Value = value; this.Left = new Node() { Value = leftVal }; this.Right = new Node() { Value = rightVal }; }