예제 #1
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;
     }
 }
예제 #2
0
        /// <summary>
        /// 定义构造函数
        /// </summary>
        /// <param name="g">有向图</param>
        public Euler(Digraph g)
        {
            Degrees degrees = new Degrees(g);

            //有向图的欧拉图判定定理,出度=入度
            for (int i = 0; i < g.V; ++i)
            {
                if (degrees.InDegree(i) != degrees.OutDegree(i))
                {
                    return;
                }
            }
            //是欧拉图
            //寻找欧拉环
            marked  = new Boolean[g.V];
            results = new Stack <Int32>();
            dfs(g, 0);
        }