mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-10 11:28:03 +00:00
Simpilfied breadth first search challenge.
This commit is contained in:
@@ -63,6 +63,18 @@
|
||||
"## Code"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%run ../bst/bst.py\n",
|
||||
"%load ../bst/bst.py"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -71,27 +83,8 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class Node(object):\n",
|
||||
"\n",
|
||||
" def __init__(self, data):\n",
|
||||
" self.data = data\n",
|
||||
" self.left = None\n",
|
||||
" self.right = None\n",
|
||||
"\n",
|
||||
" def insert(self, data):\n",
|
||||
" if data <= self.data:\n",
|
||||
" if self.left is None:\n",
|
||||
" self.left = Node(data)\n",
|
||||
" else:\n",
|
||||
" self.left.insert(data)\n",
|
||||
" else:\n",
|
||||
" if self.right is None:\n",
|
||||
" self.right = Node(data)\n",
|
||||
" else:\n",
|
||||
" self.right.insert(data)\n",
|
||||
"\n",
|
||||
" def bfs(self, visit_func):\n",
|
||||
" # TODO: Implement me"
|
||||
"def bfs(self, visit_func):\n",
|
||||
" # TODO: Implement me"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user