Move graph bfs to a class

This commit is contained in:
Donne Martin
2016-09-10 07:40:52 -04:00
parent d1d1abd3db
commit e1bf3e791a
3 changed files with 26 additions and 22 deletions

View File

@@ -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",