public Edge(Node snode, Node enode,double svalue) { this.snode = snode; this.enode = enode; this.svalue = svalue; edges = new EdgesCollection(this); }
//n为顶点数,e为边数 //public object Clone() //{ // return this.MemberwiseClone(); //} public void CreateGraph(int n, int e) { int i, j, k, w; object b, t; Graphic Graphic1 = new Graphic(); Console.Write("\n顶点数n和边数e"); for (i = 0; i < n; i++) { Console.Write("\t第" + i + "个顶点的信息:"); Node node1 = new Node(); //node1.Num = i; node1.Name = i.ToString(); Graphic1.Node.Nodes.Add(node1); } for (i = 0; i < n; i++) for (j = 0; j < n; j++) { Edge edge1 = new Edge(); edge1.Snode = Graphic1.Node.Nodes[i]; edge1.Enode = Graphic1.Node.Nodes[j]; edge1.Svalue = 0; Graphic1.Edge.Edges.Add(edge1); } for (k = 0; k < e; k++) { Console.Write("第" + k + "条边=>\n\t起点:"); b = Console.ReadLine(); Console.Write("终点"); t = Console.ReadLine(); Console.Write("权值"); w = int.Parse(Console.ReadLine()); i = 0; while (i < n && Graphic1.Node.Nodes[i].Name != b.ToString()) i++; if (i > n) { Console.Write("输入起点不存在"); Console.Error.Close(); } j = 0; while (j < n && Graphic1.Node.Nodes[j].Name != t.ToString()) j++; if (j > n) { Console.Write("输入起点不存在"); Console.Error.Close(); } Graphic1.Edge.Edges[k].Svalue = w; } }
private Node node; //点 #endregion Fields #region Constructors public Graphic() { node = new Node(); edge = new Edge(); }
private void InitNodeCollection(Node node1) { node1.Parant = this.Parent; }
private double svalue; //权值 #endregion Fields #region Constructors public Edge(Node snode,Node enode) { this.snode =snode; this.enode = enode; edges = new EdgesCollection(this); }
public void Remove(Node item) { base.List.Remove(item); }
public int IndexOf(Node item) { return base.List.IndexOf(item); }
public bool Contains(Node item) { return base.List.Contains(item); }
public void AddAt(int index, Node item) { base.List.Insert(index, item); }
public void Add(Node item) { base.List.Add(item); }