Move bst min to a class

This commit is contained in:
Donne Martin
2016-08-14 08:22:07 -04:00
parent 82c9725000
commit 857497115a
3 changed files with 50 additions and 49 deletions

View File

@@ -90,15 +90,10 @@
},
"outputs": [],
"source": [
"def create_min_bst(array):\n",
" # TODO: Implement me\n",
" # Calls _create_min_bst\n",
" pass \n",
"class MinBst(object):\n",
"\n",
"\n",
"def _create_min_bst(array, start, end):\n",
" # TODO: Implement me\n",
" pass"
" def create_min_bst(self, array):\n",
" # TODO: Implement me"
]
},
{
@@ -115,17 +110,6 @@
"**The following unit test is expected to fail until you solve the challenge.**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%run ../tree_height/height.py"
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -138,15 +122,24 @@
"from nose.tools import assert_equal\n",
"\n",
"\n",
"def height(node):\n",
" if node is None:\n",
" return 0\n",
" return 1 + max(height(node.left),\n",
" height(node.right))\n",
"\n",
"\n",
"class TestBstMin(object):\n",
"\n",
" def test_bst_min(self):\n",
" min_bst = MinBst()\n",
" array = [0, 1, 2, 3, 4, 5, 6]\n",
" root = create_min_bst(array)\n",
" root = min_bst.create_min_bst(array)\n",
" assert_equal(height(root), 3)\n",
"\n",
" min_bst = MinBst()\n",
" array = [0, 1, 2, 3, 4, 5, 6, 7]\n",
" root = create_min_bst(array)\n",
" root = min_bst.create_min_bst(array)\n",
" assert_equal(height(root), 4)\n",
"\n",
" print('Success: test_bst_min')\n",