Beispiel #1
0
        static void Main(string[] args)
        {
            while (true)
            {
                Console.WriteLine("Введите глубину дерева N ");
                int N = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Введите максимальное кол-во потомков K(<9) ");
                int K = Convert.ToInt32(Console.ReadLine());


                if (K >= 9)
                {
                    Console.WriteLine("Максимальное кол-во потомков - 8");
                }
                else
                {
                    TreeClass tc = new TreeClass();
                    tc.CreateTree(N, K);

                    string path = ReadValueFromConsole("путь к файлу: ");
                    Console.WriteLine();

                    WriteToFile(path, tc);

                    Console.WriteLine();
                    Console.WriteLine("Все возможные пути, ведущие от корня к листьям, сохранены в файл");
                }
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine();
            }
        }
Beispiel #2
0
        public static void WriteToFile(string path, TreeClass tc)
        {
            List <string> allPaths = new List <string>();

            allPaths = tc.FindAllPaths();

            FileStream   file = new FileStream(path, FileMode.OpenOrCreate);
            StreamWriter f    = new StreamWriter(file);

            for (int i = 0; i < allPaths.Count; i++)
            {
                f.WriteLine(allPaths[i]);
            }
            f.Close();
            file.Close();
        }