mirror of
https://github.com/donnemartin/interactive-coding-challenges.git
synced 2024-03-22 13:11:13 +08:00
parent
eb8547d8bd
commit
3d4ae5c22f
|
@ -17,14 +17,13 @@ class Bst(object):
|
||||||
|
|
||||||
def insert(self, data):
|
def insert(self, data):
|
||||||
if data is None:
|
if data is None:
|
||||||
raise Exception('Data cannot be None')
|
raise TypeError('data cannot be None')
|
||||||
if self.root is None:
|
if self.root is None:
|
||||||
self.root = Node(data)
|
self.root = Node(data)
|
||||||
return self.root
|
return self.root
|
||||||
return self._insert(self.root, data)
|
return self._insert(self.root, data)
|
||||||
|
|
||||||
def _insert(self, node, data):
|
def _insert(self, node, data):
|
||||||
# Constraint: Assume we are working with valid ints
|
|
||||||
if node is None:
|
if node is None:
|
||||||
return Node(data)
|
return Node(data)
|
||||||
if data <= node.data:
|
if data <= node.data:
|
||||||
|
|
|
@ -132,14 +132,13 @@
|
||||||
"\n",
|
"\n",
|
||||||
" def insert(self, data):\n",
|
" def insert(self, data):\n",
|
||||||
" if data is None:\n",
|
" if data is None:\n",
|
||||||
" raise Exception('Data cannot be None')\n",
|
" raise TypeError('data cannot be None')\n",
|
||||||
" if self.root is None:\n",
|
" if self.root is None:\n",
|
||||||
" self.root = Node(data)\n",
|
" self.root = Node(data)\n",
|
||||||
" return self.root\n",
|
" return self.root\n",
|
||||||
" return self._insert(self.root, data)\n",
|
" return self._insert(self.root, data)\n",
|
||||||
"\n",
|
"\n",
|
||||||
" def _insert(self, node, data):\n",
|
" def _insert(self, node, data):\n",
|
||||||
" # Constraint: Assume we are working with valid ints\n",
|
|
||||||
" if node is None:\n",
|
" if node is None:\n",
|
||||||
" return Node(data)\n",
|
" return Node(data)\n",
|
||||||
" if data <= node.data:\n",
|
" if data <= node.data:\n",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user