예제 #1
0
        public static DirectedGraph ReadFromTxtFile(string fileName)
        {
            StreamReader inputFile = new StreamReader(fileName);
            string fileContent = inputFile.ReadToEnd();

            string[] inputData = fileContent.Split(new string[] { " ", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

            var result = new DirectedGraph(int.Parse(inputData[0]));

            int edgesCount = int.Parse(inputData[1]);
            for (int i = 0; i < edgesCount; ++i)
            {
                DirectedEdge edge = new DirectedEdge(int.Parse(inputData[i * 2 + 2]) - 1, int.Parse(inputData[i * 2 + 3]) - 1);
                result[edge.Begin].Add(edge);
            }

            return result;
        }
예제 #2
0
        public static DirectedGraph ReadFromConsole()
        {
            AllocConsole();

            Console.Write("Enter a number of vertices, please: ");
            int verticesCount = int.Parse(Console.ReadLine());
            DirectedGraph result = new DirectedGraph(verticesCount);

            Console.Write("Enter a number of edges, please: ");
            int edgesCount = int.Parse(Console.ReadLine());

            for (int i = 0; i < edgesCount; ++i)
            {
                Console.Write("Enter begin and end of {0} edge, please: ", i + 1);
                string[] inputData = Console.ReadLine().Split(new string[]{" "}, StringSplitOptions.RemoveEmptyEntries);

                DirectedEdge edge = new DirectedEdge(int.Parse(inputData[0]) - 1, int.Parse(inputData[1]) - 1);
                result[edge.Begin].Add(edge);
            }

            FreeConsole();
            return result;
        }
예제 #3
0
 public DirectedEdge(DirectedEdge edge)
 {
     Begin = edge.Begin;
     End = edge.End;
 }
예제 #4
0
 public void AddEdge(DirectedEdge edge)
 {
     Graph[edge.Begin].Add(edge);
     ++EdgesCount;
 }
예제 #5
0
 public void AddEdge(DirectedEdge edge)
 {
     Graph[edge.Begin].Add(edge);
     ++EdgesCount;
 }
예제 #6
0
 public DirectedEdge(DirectedEdge edge)
 {
     Begin = edge.Begin;
     End   = edge.End;
 }