Skip to content

Commit c3a3482

Browse files
committed
adds dfs and bfs for codesandbox
1 parent 810a831 commit c3a3482

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

graphs/breadthFirstSearch.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,14 @@ nodes.forEach(node => {
136136
})
137137

138138
edges.forEach((...nodes) => {
139-
graph.addEdge(...nodes)
139+
// graph.addEdge(...nodes)
140+
graph.addEdge(nodes[0][0], nodes[0][1])
141+
})
142+
143+
graph.bfs('a', node => {
144+
console.log(node.key)
140145
})
141146

142-
console.log(graph.print())
143147

144148
exports.createNode = createNode
145149
exports.createGraph = createGraph

graphs/depthFirstSearch.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,12 @@ nodes.forEach(node => {
136136
})
137137

138138
edges.forEach((...nodes) => {
139-
graph.addEdge(...nodes)
139+
// graph.addEdge(...nodes)
140+
graph.addEdge(nodes[0][0], nodes[0][1])
141+
})
142+
143+
graph.dfs('a', node => {
144+
console.log(node.key)
140145
})
141146

142147
exports.createNode = createNode

0 commit comments

Comments
 (0)