mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-10 03:18:02 +00:00
Revised bfs challenge to be more self contained for simplicity.
This commit is contained in:
@@ -71,7 +71,24 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class MyNode(Node):\n",
|
||||
"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"
|
||||
|
||||
Reference in New Issue
Block a user