MCPcopy Index your code
hub / github.com/TheAlgorithms/JavaScript / example

Function example

Data-Structures/Graph/Graph.js:74–101  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

72}
73
74const example = () => {
75 const g = new Graph()
76 g.addVertex(1)
77 g.addVertex(2)
78 g.addVertex(3)
79 g.addVertex(4)
80 g.addVertex(5)
81 g.addEdge(1, 2)
82 g.addEdge(1, 3)
83 g.addEdge(2, 4)
84 g.addEdge(2, 5)
85
86 // Graph
87 // 1 -> 2 3
88 // 2 -> 1 4 5
89 // 3 -> 1
90 // 4 -> 2
91 // 5 -> 2
92
93 // Printing the adjacency list
94 // g.printGraph()
95
96 // Breadth first search at node 1
97 g.bfs(1)
98
99 // Depth first search at node 1
100 g.dfs(1)
101}
102
103export { Graph, example }

Callers

nothing calls this directly

Calls 4

addVertexMethod · 0.95
addEdgeMethod · 0.95
bfsMethod · 0.95
dfsMethod · 0.95

Tested by

no test coverage detected