Beispiel #1
0
        public static void ConvertTreeToMatrix(Node root)
        {
            int h      = HeightOfBinaryTree.GetHeight(root);
            int column = (int)Math.Pow(2, h) - 1;

            int[,] arr = new int[h, column];

            ConvertTreeToMatrixHelper(root, arr, 0, arr.GetLength(1) - 1, 0);

            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < column; j++)
                {
                    Console.Write(string.Format("{0} ", arr[i, j]));
                }
                Console.Write(Environment.NewLine + Environment.NewLine);
            }
        }
        public static int GetMaxWidth(Node root)
        {
            int h = HeightOfBinaryTree.GetHeight(root);

            int[] levelWidth = new int[h];
            GetMaxWidth(root, levelWidth, 0);

            var max = 0;

            for (int i = 0; i < levelWidth.Length; i++)
            {
                if (max < levelWidth[i])
                {
                    max = levelWidth[i];
                }
            }
            return(max);
        }
        public static int FindMinimumSumLevel(Node root)
        {
            int h = HeightOfBinaryTree.GetHeight(root);

            int[] levelSum = new int[h];
            GetSum(root, levelSum, 0);

            int min        = levelSum[0];
            int LevelIndex = 0;

            for (int i = 1; i < levelSum.Length; i++)
            {
                if (levelSum[i] < min)
                {
                    LevelIndex = i;
                    min        = levelSum[i];
                }
            }
            return(LevelIndex + 1);
        }