Exemplo n.º 1
0
 /// <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;
 }
Exemplo n.º 2
0
 public void DFSPostorder(Node n, Action<Node> visit)
 {
     if (n == null)
         return;
     DFSPostorder(n.Left, visit);
     DFSPostorder(n.Right, visit);
     visit(n);
 }
Exemplo n.º 3
0
        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);

        }
Exemplo n.º 4
0
 public Node(string value, Node leftVal = null, Node rightVal = null)
 {
     this.Value = value;
     this.Left = leftVal;
     this.Right = rightVal;
 }
Exemplo n.º 5
0
 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 };
 }