AddWeightedEdge will add a new weighted edge between the provided vertices in the graph
(one, two, weight int)
| 40 | |
| 41 | // AddWeightedEdge will add a new weighted edge between the provided vertices in the graph |
| 42 | func (g *Graph) AddWeightedEdge(one, two, weight int) { |
| 43 | // Add vertices: one and two to the graph if they are not present |
| 44 | g.AddVertex(one) |
| 45 | g.AddVertex(two) |
| 46 | |
| 47 | // And finally add the edges |
| 48 | // one->two and two->one for undirected graph |
| 49 | // one->two for directed graphs |
| 50 | g.edges[one][two] = weight |
| 51 | if !g.Directed { |
| 52 | g.edges[two][one] = weight |
| 53 | } |
| 54 | } |