Exemple #1
0
        /// <summary>
        /// 建全一个有向图对象
        /// (不是建立 ^_^)
        /// </summary>
        /// <param name="G"></param>
        public void CreateALGraph(ALGraph G)
        {
            int      i, j, k;
            EdgeNode s;

            for (int vnc = 0; vnc < G.VertexNodeCount; vnc++)
            {
                VertexNode cuVN = new VertexNode();
                Console.Write("请输入顶点的编号 : ");
                cuVN.vertex    = Console.ReadLine();
                cuVN.firstedge = null;
                G.AdjList[vnc] = cuVN;
            }

            for (k = 0; k < G.BordeCount; k++)
            {
                Console.Write("请输入边开始顶点的序号 : ");
                i = int.Parse(Console.ReadLine()) - 1;
                Console.Write("请输入边结束顶点的序号 : ");
                j        = int.Parse(Console.ReadLine()) - 1;
                s        = new EdgeNode();
                s.adjvex = j;
                s.next   = G.AdjList[i].firstedge;
                //邻接表头插法
                G.AdjList[i].firstedge = s;
                //建立无向图
                if (G.theType == GraphType.UnDiGraph)
                {
                    s        = new EdgeNode();
                    s.adjvex = i;
                    s.next   = G.AdjList[j].firstedge;
                    G.AdjList[j].firstedge = s;
                }
            }
        }
Exemple #2
0
 public VertexNode()
 {
     firstedge = null;
 }
Exemple #3
0
 public EdgeNode()
 {
     next = null;
 }