Ejemplo n.º 1
0
    public static List <string> Preorder_Traversal(Program.TreeNode tree, List <string> list)
    {
        if (tree == null)
        {
            return(list);
        }
        list.Add(tree.val);

        if (tree.left != null)
        {
            Preorder_Traversal(tree.left, list);
        }

        if (tree.right != null)
        {
            Preorder_Traversal(tree.right, list);
        }

        //System.Console.WriteLine("Recursive");
        return(list);
    }
Ejemplo n.º 2
0
        public int MaxDepth(Program.TreeNode root)
        {
            if (root == null)
            {
                return(0);
            }
            else
            {
                /* compute the depth of each subtree */
                int leftDepth  = MaxDepth(root.left);
                int rightDepth = MaxDepth(root.right);

                /* use the larger one */
                if (leftDepth > rightDepth)
                {
                    return(leftDepth + 1);
                }
                else
                {
                    return(rightDepth + 1);
                }
            }
        }