Move tree height to a class

This commit is contained in:
Donne Martin
2016-08-14 08:29:25 -04:00
parent b4ed90e649
commit 9176ffe214
4 changed files with 42 additions and 56 deletions

View File

@@ -88,9 +88,11 @@
},
"outputs": [],
"source": [
"def height(node):\n",
" # TODO: Implement me\n",
" pass"
"class BstHeight(Bst):\n",
"\n",
" def height(self, node):\n",
" # TODO: Implement me\n",
" pass"
]
},
{
@@ -122,13 +124,13 @@
"class TestHeight(object):\n",
"\n",
" def test_height(self):\n",
" root = Node(5)\n",
" assert_equal(height(root), 1)\n",
" insert(root, 2)\n",
" insert(root, 8)\n",
" insert(root, 1)\n",
" insert(root, 3)\n",
" assert_equal(height(root), 3)\n",
" bst = BstHeight(Node(5))\n",
" assert_equal(bst.height(bst.root), 1)\n",
" bst.insert(2)\n",
" bst.insert(8)\n",
" bst.insert(1)\n",
" bst.insert(3)\n",
" assert_equal(bst.height(bst.root), 3)\n",
"\n",
" print('Success: test_height')\n",
"\n",