Skip to content

Instantly share code, notes, and snippets.

@GAierken
Created July 20, 2020 02:15
Show Gist options
  • Save GAierken/001ad5fcbde4744cd37efbde0d256e92 to your computer and use it in GitHub Desktop.
Save GAierken/001ad5fcbde4744cd37efbde0d256e92 to your computer and use it in GitHub Desktop.
breathFirst(start){
const queue = [start]
const result = []
const visited = {}
let currentVertex
visited[start] = true
while(queue.length){
currentVertex = queue.shift()
result.push(currentVertex)
this.adjacencyList[currentVertex].forEach((neighbor) => {
if(!visited[neighbor]){
visited[neighbor] = true
queue.push(neighbor)
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment