Created
December 15, 2018 23:45
-
-
Save rajatk16/cef4425ccb7850761834392c0ac54b4b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| breadthFirst(startingNode, neighborVisit) { | |
| const firstNode = this.searchNode(startingNode) | |
| const visitedNode = nodes.reduce((sum, node) => { | |
| sum[node.id] = false | |
| return sum | |
| }, {}) | |
| const queue = queueCreator() | |
| queue.add(firstNode) | |
| while (!queue.empty()) { | |
| const temp = queue.remove() | |
| if (!visitedNode[temp.id]) { | |
| neighborVisit(temp) | |
| visitedNode[temp.id] = true | |
| } | |
| temp.neighbors.forEach(node => { | |
| if(!visitedNode[node.id]) { | |
| queue.add(node) | |
| } | |
| }) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment