Beispiel #1
0
        public void AddEdge(T from, T to)
        {
            HeadNode <T> fromVer = Find(from);

            if (fromVer == null)
            {
                throw new ArgumentException("头顶点不存在");
            }
            HeadNode <T> toVer = Find(to);

            if (toVer == null)
            {
                throw new ArgumentException("尾顶点不存在");
            }
            AddDirectedEdge(fromVer, toVer);
            AddDirectedEdge(toVer, fromVer);
        }
Beispiel #2
0
 public void AddDirectedEdge(HeadNode <T> fromVer, HeadNode <T> toVer)
 {
     if (fromVer.FirstEdge == null)
     {
         fromVer.FirstEdge = new ArcNode <T>(toVer);
     }
     else
     {
         ArcNode <T> tem, node = fromVer.FirstEdge;
         do
         {
             if (node.headNode.Equals(toVer.Data))
             {
                 throw new ArgumentException("添加了重复边!");
             }
             tem  = node;
             node = node.Next;
         } while (node != null);
         tem.Next = new ArcNode <T>(toVer);
     }
 }
Beispiel #3
0
 //弧上的权值
 public ArcNode(HeadNode <T> value)
 {
     headNode = value;
 }