Exemplo n.º 1
0
        private static void PrintTree(dynamic combination, TreeColors pathColors)
        {
            double maxCharLen = 0;

            foreach (var line in BinaryTree)
            {
                foreach (var number in line)
                {
                    maxCharLen = Math.Max(maxCharLen, number.ToString().Length);
                }
            }
            int       step    = (int)Math.Ceiling(maxCharLen / 2);
            int       linePad = step * (BinaryTree.Length - 1);
            TreeColor color   = pathColors.GetRandom();

            for (int r = 0; r <= BinaryTree.Length - 1; r++)
            {
                Console.Write(new string(' ', linePad));
                linePad = linePad - step;
                for (int c = 0; c <= BinaryTree[r].Length - 1; c++)
                {
                    if (combination.Cols[r] == c)
                    {
                        Console.ForegroundColor = color.ForegroundColor;
                        Console.BackgroundColor = color.BackgroundColor;
                        Console.Write($"{BinaryTree[r][c].ToString().PadLeft((int)maxCharLen, '0')}");
                        Console.ResetColor();
                        Console.Write(" ");
                    }
                    else
                    {
                        Console.Write($"{BinaryTree[r][c].ToString().PadLeft((int)maxCharLen, '0')} ");
                    }
                }
                Console.WriteLine();
            }
        }