bottomUpTree() public static method

public static bottomUpTree ( int item, int depth ) : TreeNode
item int
depth int
return TreeNode
Ejemplo n.º 1
0
        public static void Main(String[] args)
        {
            int n = 12;//DEPTH HARDCPDED !
            // if (args.Length > 0) n = Int32.Parse(args[0]);

            int maxDepth     = Math.Max(minDepth + 2, n);
            int stretchDepth = maxDepth + 1;

            int check = (TreeNode.bottomUpTree(0, stretchDepth)).itemCheck();

            Console.Write("stretch tree of depth ");
            Console.Write(stretchDepth);
            Console.Write("\t check: ");
            Console.WriteLine(check);

            TreeNode longLivedTree = TreeNode.bottomUpTree(0, maxDepth);

            for (int depth = minDepth; depth <= maxDepth; depth += 2)
            {
                int iterations = 1 << (maxDepth - depth + minDepth);

                check = 0;
                for (int i = 1; i <= iterations; i++)
                {
                    check += (TreeNode.bottomUpTree(i, depth)).itemCheck();
                    check += (TreeNode.bottomUpTree(-i, depth)).itemCheck();
                }


                Console.Write(iterations * 2);
                Console.Write("\t trees of depth ");
                Console.Write(depth);
                Console.Write("\t check: ");
                Console.WriteLine(check);
            }

            Console.Write("long lived tree of depth ");
            Console.Write(maxDepth);
            Console.Write("\t check: ");
            Console.WriteLine(longLivedTree.itemCheck());
        }