MCPcopy Index your code
hub / github.com/TheAlgorithms/Go / AddWeightedEdge

Method AddWeightedEdge

graph/graph.go:42–54  ·  view source on GitHub ↗

AddWeightedEdge will add a new weighted edge between the provided vertices in the graph

(one, two, weight int)

Source from the content-addressed store, hash-verified

40
41// AddWeightedEdge will add a new weighted edge between the provided vertices in the graph
42func (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}

Callers 6

TestDijkstraFunction · 0.95
AddEdgeMethod · 0.95
TestDirectedGraphFunction · 0.80
TestUndirectedGraphFunction · 0.80
TestPrimMSTFunction · 0.80
TestBellmanfordFunction · 0.80

Calls 1

AddVertexMethod · 0.95

Tested by 5

TestDijkstraFunction · 0.76
TestDirectedGraphFunction · 0.64
TestUndirectedGraphFunction · 0.64
TestPrimMSTFunction · 0.64
TestBellmanfordFunction · 0.64