Created
July 20, 2020 02:15
-
-
Save GAierken/001ad5fcbde4744cd37efbde0d256e92 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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