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

Method BFS

Data-Structures/Graph/Graph3.js:83–105  ·  view source on GitHub ↗
(start)

Source from the content-addressed store, hash-verified

81 }
82
83 BFS(start) {
84 if (!start) return null
85
86 const queue = [start]
87 const visited = {}
88 visited[start] = true
89
90 let currentVertex
91 const result = []
92
93 while (queue.length) {
94 currentVertex = queue.shift()
95 result.push(currentVertex)
96
97 this.adjacencyObject[currentVertex].forEach((neighbor) => {
98 if (!visited[neighbor]) {
99 visited[neighbor] = true
100 queue.push(neighbor)
101 }
102 })
103 }
104 return result
105 }
106}
107
108export { Graph }

Callers 1

Graph3.test.jsFile · 0.80

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected