public void CreateDirectionalConnection(T val1, T val2, int weight) // val1 -> val2 , with weighted edge { if (!this.DoesNodeExist(val1) || !this.DoesNodeExist(val2)) { throw new Exception("No elemets found :( "); } if (this.EdgeExists(val1, val2)) { return; } Node <T> node1 = GetNode(val1); Node <T> node2 = GetNode(val2); node1.NeighbourNodes.Add(node2); WeightedEdge <T> edge = new WeightedEdge <T>(node1, node2, weight); WeightedEdges.Add(edge); }
public void MakeConnected(T val1, T val2, int weight) //created 2-way weighted connection { if (!this.DoesNodeExist(val1) || !this.DoesNodeExist(val2)) { throw new Exception("No elemets found :( "); } if (this.AreConnected(val1, val2)) { return; } Node <T> n1 = GetNode(val1); Node <T> n2 = GetNode(val2); n1.NeighbourNodes.Add(n2); n2.NeighbourNodes.Add(n1); WeightedEdge <T> e1 = new WeightedEdge <T>(n1, n2, weight); WeightedEdge <T> e2 = new WeightedEdge <T>(n2, n1, weight); WeightedEdges.Add(e1); WeightedEdges.Add(e2); }