diff --git a/graphs_trees/bst_validate/bst_validate_challenge.ipynb b/graphs_trees/bst_validate/bst_validate_challenge.ipynb index 2e385cb..c2f46c7 100644 --- a/graphs_trees/bst_validate/bst_validate_challenge.ipynb +++ b/graphs_trees/bst_validate/bst_validate_challenge.ipynb @@ -91,50 +91,8 @@ "metadata": {}, "outputs": [], "source": [ - "# %load ../bst/bst.py\n", - "class Node(object):\n", - "\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" + "%run ../bst/bst.py\n", + "%load ../bst/bst.py" ] }, { diff --git a/graphs_trees/tree_dfs/dfs_challenge.ipynb b/graphs_trees/tree_dfs/dfs_challenge.ipynb index 629de37..fec275a 100644 --- a/graphs_trees/tree_dfs/dfs_challenge.ipynb +++ b/graphs_trees/tree_dfs/dfs_challenge.ipynb @@ -85,50 +85,8 @@ "metadata": {}, "outputs": [], "source": [ - "# %load ../bst/bst.py\n", - "class Node(object):\n", - "\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" + "%run ../bst/bst.py\n", + "%load ../bst/bst.py" ] }, {