Remove graphs_trees solutions from challenges (#285)

This commit is contained in:
Donne Martin 2020-07-17 20:45:23 -04:00 committed by GitHub
parent a072a7e573
commit 9ef6d6da0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 88 deletions

View File

@ -91,50 +91,8 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"# %load ../bst/bst.py\n", "%run ../bst/bst.py\n",
"class Node(object):\n", "%load ../bst/bst.py"
"\n",
" def __init__(self, data):\n",
" self.data = data\n",
" self.left = None\n",
" self.right = None\n",
" self.parent = None\n",
"\n",
" def __repr__(self):\n",
" return str(self.data)\n",
"\n",
"\n",
"class Bst(object):\n",
"\n",
" def __init__(self, root=None):\n",
" self.root = root\n",
"\n",
" def insert(self, data):\n",
" if data is None:\n",
" raise TypeError('data cannot be None')\n",
" if self.root is None:\n",
" self.root = Node(data)\n",
" return self.root\n",
" else:\n",
" return self._insert(self.root, data)\n",
"\n",
" def _insert(self, node, data):\n",
" if node is None:\n",
" return Node(data)\n",
" if data <= node.data:\n",
" if node.left is None:\n",
" node.left = self._insert(node.left, data)\n",
" node.left.parent = node\n",
" return node.left\n",
" else:\n",
" return self._insert(node.left, data)\n",
" else:\n",
" if node.right is None:\n",
" node.right = self._insert(node.right, data)\n",
" node.right.parent = node\n",
" return node.right\n",
" else:\n",
" return self._insert(node.right, data)\n"
] ]
}, },
{ {

View File

@ -85,50 +85,8 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"# %load ../bst/bst.py\n", "%run ../bst/bst.py\n",
"class Node(object):\n", "%load ../bst/bst.py"
"\n",
" def __init__(self, data):\n",
" self.data = data\n",
" self.left = None\n",
" self.right = None\n",
" self.parent = None\n",
"\n",
" def __repr__(self):\n",
" return str(self.data)\n",
"\n",
"\n",
"class Bst(object):\n",
"\n",
" def __init__(self, root=None):\n",
" self.root = root\n",
"\n",
" def insert(self, data):\n",
" if data is None:\n",
" raise TypeError('data cannot be None')\n",
" if self.root is None:\n",
" self.root = Node(data)\n",
" return self.root\n",
" else:\n",
" return self._insert(self.root, data)\n",
"\n",
" def _insert(self, node, data):\n",
" if node is None:\n",
" return Node(data)\n",
" if data <= node.data:\n",
" if node.left is None:\n",
" node.left = self._insert(node.left, data)\n",
" node.left.parent = node\n",
" return node.left\n",
" else:\n",
" return self._insert(node.left, data)\n",
" else:\n",
" if node.right is None:\n",
" node.right = self._insert(node.right, data)\n",
" node.right.parent = node\n",
" return node.right\n",
" else:\n",
" return self._insert(node.right, data)\n"
] ]
}, },
{ {