mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-05 00:48:03 +00:00
Simplified challenge coding and unit tests by working with the node directly as opposed to node.id or node.data, which is more natural when writing coding challenges.
This commit is contained in:
@@ -5,6 +5,10 @@ class Node(object):
|
||||
self.left = None
|
||||
self.right = None
|
||||
|
||||
def __str__(self):
|
||||
return str(self.data)
|
||||
|
||||
|
||||
def insert(root, data):
|
||||
if data <= root.data:
|
||||
if root.left is None:
|
||||
@@ -15,4 +19,4 @@ def insert(root, data):
|
||||
if root.right is None:
|
||||
root.right = Node(data)
|
||||
else:
|
||||
insert(root.right, data)
|
||||
insert(root.right, data)
|
||||
@@ -91,8 +91,17 @@
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Overwriting bst.py\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"%%writefile bst.py\n",
|
||||
"class Node(object):\n",
|
||||
"\n",
|
||||
" def __init__(self, data):\n",
|
||||
@@ -100,6 +109,9 @@
|
||||
" self.left = None\n",
|
||||
" self.right = None\n",
|
||||
"\n",
|
||||
" def __str__(self):\n",
|
||||
" return str(self.data)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def insert(root, data):\n",
|
||||
" if data <= root.data:\n",
|
||||
@@ -114,6 +126,17 @@
|
||||
" insert(root.right, data)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%run bst.py"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
@@ -123,7 +146,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"execution_count": 3,
|
||||
"metadata": {
|
||||
"collapsed": true
|
||||
},
|
||||
@@ -134,7 +157,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"execution_count": 4,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
@@ -145,7 +168,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"execution_count": 5,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
@@ -200,7 +223,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"execution_count": 6,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user