Example #1
0
        public void buildGraph(string filename)
        {
            using (StreamReader file = new StreamReader(filename))
            {
                string line = null;
                char[] spaceDelim = { ' ' };
                int numRouters = int.Parse(file.ReadLine());

                for (int i = 0; i < numRouters; i++)
                {
                    line = file.ReadLine();
                    Router r = new Router(numRouters);
                    r.distance[i] = 0;      // distance to itself is 0
                    r.nextHop[i] = i;       // next hop to itself is itself

                    string[] neighbors = line.Split(spaceDelim);
                    for (int j = 1; j < neighbors.Length; j += 2)
                    {
                        r.addNeighbor(neighbors[j][0] - 'A', neighbors[j + 1][0] - '0');
                    }

                    this.graph.Add(r);
                }
            }
        }