Пример #1
0
        public void Run()
        {
            Console.WriteLine("Choose file:"); // Prompt
            Console.WriteLine("1 - jobs.txt"); // Prompt
            Console.WriteLine("or quit"); // Prompt

            var fileNumber = Console.ReadLine();
            string fileName;
            char delimiter;
            switch (fileNumber)
            {
                case "1":
                    fileName = "jobs.txt";
                    delimiter = '/';
                    break;
                case "quit":
                    return;
                default:
                    return;
            }

            var @in = new In($"Files\\Graphs\\{fileName}");
            var lines = !fileName.EndsWith("zip") ? @in.ReadAllLines() : @in.ReadAllLinesFromZip();

            var sg = new SymbolDigraph(lines, delimiter);
            Console.WriteLine(sg.G);

            var topological = new Topological(sg.G);
            foreach (int v in topological.Order())
            {
                Console.WriteLine(sg.Name(v));
            }

            Console.ReadLine();
        }
Пример #2
0
        public void Run()
        {
            Console.WriteLine("Choose file:"); // Prompt
            Console.WriteLine("1 - routes.txt"); // Prompt
            Console.WriteLine("2 - movies.txt"); // Prompt
            //Console.WriteLine("3 - largeG.zip"); // Prompt
            Console.WriteLine("or quit"); // Prompt

            var fileNumber = Console.ReadLine();
            string fileName;
            char delimiter;
            List<string> names;
            switch (fileNumber)
            {
                case "1":
                    fileName = "routes.txt";
                    delimiter = '\u0020';
                    names = new List<string> {"JFK", "ATL", "LAX"};
                    break;
                case "2":
                    fileName = "movies.txt";
                    delimiter = '/';
                    names = new List<string> { "Tin Men (1987)", "Bacon, Kevin" };
                    break;
                //case "3":
                //    fieName = "largeG.zip";
                //    break;
                case "quit":
                    return;
                default:
                    return;
            }

            var @in = new In($"Files\\Graphs\\{fileName}");
            var lines = !fileName.EndsWith("zip") ? @in.ReadAllLines() : @in.ReadAllLinesFromZip();

            var sg = new SymbolDigraph(lines, delimiter);
            var digraph = sg.G;

            foreach (var name in names)
            {
                Console.WriteLine($"{name}");
                if (sg.Contains(name))
                {
                    var s = sg.Index(name);
                    foreach (int v in digraph.Adj(s))
                    {
                        Console.WriteLine($"   {sg.Name(v)}");
                    }
                }
                else
                {
                    Console.WriteLine($"input not contain '{name}'");
                }
            }
            Console.ReadLine();
        }