コード例 #1
0
ファイル: Demo.cs プロジェクト: RamiAmaire/TelerikAcademy
        public static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            TreeNode<int>[] nodes = SaveNodes(N);
            GenNodesConnections(N, nodes);

            Tree<int> tree = new Tree<int>(nodes);

            // Task 1
            TreeNode<int> root = tree.Root;
            Console.WriteLine("Root : {0}", root.Value);
            Console.WriteLine(new string('-', 40));

            // Task 2
            List<TreeNode<int>> leafs = tree.FindAllLeafs();
            Print(leafs, "All leafs : ");
            Console.WriteLine(new string('-', 40));

            // Task 3
            List<TreeNode<int>> middleNodes = tree.FindAllMiddleNodes();
            Print(middleNodes, "All middle nodes : ");
            Console.WriteLine(new string('-', 40));

            // Task 4
            int longestPath = tree.FindLongestPath(root);
            Console.WriteLine("The longest path : {0}", longestPath);
            Console.WriteLine(new string('-', 40));

            int S = 10;

            // Task 5
            tree.PrintAllPathsWithSumS(S);

            // Task 6
            tree.PrintAllSubTreesWithSumS(S);
        }