public IDirectedGraph Reverse()
        {
            Digraph digraph = new Digraph(V);

            for (int i = 0; i < V; ++i)
            {
                foreach (int j in Adj(i))
                {
                    digraph.AddEdge(j, i);
                }
            }
            return(digraph);
        }
Exemple #2
0
 internal string[] keys;               //保存对应索引的名称
 public SymbolGraph(string filename, char delimiter)
 {
     st = new Dictionary <string, int>();//符号和符号的编号的映射
     try
     {
         var    reader  = new System.IO.StreamReader(filename);
         string oneline = reader.ReadLine();
         while (oneline != null)
         {
             string[] vw = oneline.Split(delimiter);
             for (int i = 0; i < vw.Length; ++i)
             {
                 if (!Contains(vw[i]))
                 {
                     st.Add(vw[i], st.Count);
                 }
             }
             oneline = reader.ReadLine();
         }
         keys = new string[st.Count];
         G    = new Digraph(st.Count);
         foreach (var item in st)
         {
             keys[item.Value] = item.Key;
         }
         //重新定位
         reader.BaseStream.Seek(0, SeekOrigin.Begin);
         //添加边
         oneline = reader.ReadLine();
         while (oneline != null)
         {
             string[] vetx = oneline.Split(delimiter);
             int      v    = st[vetx[0]];
             for (int i = 1; i < vetx.Length; ++i)
             {
                 G.AddEdge(v, st[vetx[i]]);
             }
             oneline = reader.ReadLine();
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         throw e;
     }
 }