mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-13 12:58:02 +00:00
Move graph bfs to a class
This commit is contained in:
@@ -103,9 +103,11 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def bfs(root, visit_func):\n",
|
||||
" # TODO: Implement me\n",
|
||||
" pass"
|
||||
"class GraphBfs(Graph):\n",
|
||||
"\n",
|
||||
" def bfs(self, root, visit_func):\n",
|
||||
" # TODO: Implement me\n",
|
||||
" pass"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -152,7 +154,7 @@
|
||||
"\n",
|
||||
" def test_bfs(self):\n",
|
||||
" nodes = []\n",
|
||||
" graph = Graph()\n",
|
||||
" graph = GraphBfs()\n",
|
||||
" for id in range(0, 6):\n",
|
||||
" nodes.append(graph.add_node(id))\n",
|
||||
" graph.add_edge(0, 1, 5)\n",
|
||||
@@ -163,7 +165,7 @@
|
||||
" graph.add_edge(2, 1, 6)\n",
|
||||
" graph.add_edge(3, 2, 7)\n",
|
||||
" graph.add_edge(3, 4, 8)\n",
|
||||
" bfs(nodes[0], self.results.add_result)\n",
|
||||
" graph.bfs(nodes[0], self.results.add_result)\n",
|
||||
" assert_equal(str(self.results), \"[0, 1, 4, 5, 3, 2]\")\n",
|
||||
"\n",
|
||||
" print('Success: test_bfs')\n",
|
||||
|
||||
Reference in New Issue
Block a user