Last active
July 30, 2018 01:49
-
-
Save ziyoshams/c37d1fcf075de7c0345dc049e2006b13 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
// HELPER FUNCTION | |
createVisitedObject(){ | |
let arr = {}; | |
for(let key of this.AdjList.keys()){ | |
arr[key] = false; | |
} | |
return arr; | |
} | |
// Breadth First Search | |
bfs(startingNode){ | |
let visited = this.createVisitedObject(); | |
let q = []; | |
visited[startingNode] = true; | |
q.push(startingNode); | |
while(q.length){ | |
let current = q.pop() | |
console.log(current); | |
let arr = this.AdjList.get(current); | |
for(let elem of arr){ | |
if(!visited[elem]){ | |
visited[elem] = true; | |
q.unshift(elem) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment