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); } }
public string asString() { string outputstring = string.Empty; foreach (var HeadNode in _items) { if (HeadNode != null) { outputstring += string.Format("顶点:{0}", HeadNode.Data); if (HeadNode.FirstEdge != null) { ArcNode <T> tem = HeadNode.FirstEdge; while (tem != null) { outputstring += tem.headNode.Data.ToString(); tem = tem.Next; } } } outputstring += "\r\n"; } return(outputstring); }