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

Method AddVertex

graph/graph.go:24–33  ·  view source on GitHub ↗

AddVertex will add a new vertex in the graph. If the vertex already exists it will do nothing.

(v int)

Source from the content-addressed store, hash-verified

22// AddVertex will add a new vertex in the graph.
23// If the vertex already exists it will do nothing.
24func (g *Graph) AddVertex(v int) {
25 if g.edges == nil {
26 g.edges = make(map[int]map[int]int)
27 }
28
29 // Check if vertex is present or not
30 if _, ok := g.edges[v]; !ok {
31 g.edges[v] = make(map[int]int)
32 }
33}
34
35// AddEdge will add a new edge between the provided vertices in the graph
36func (g *Graph) AddEdge(one, two int) {

Callers 1

AddWeightedEdgeMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected