Skip to content

Commit d919924

Browse files
committed
Resolving pre-commit-hook changes
1 parent e4ae92e commit d919924

File tree

1 file changed

+30
-28
lines changed

1 file changed

+30
-28
lines changed

data_structures/binary_tree/binary_search_tree.py

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ def inorder(self, arr: list, node: Node):
152152
def find_kth_smallest(self, k: int, node: Node) -> int:
153153
"""Return the kth smallest element in a binary search tree"""
154154
arr: list = []
155-
self.inorder(arr, node) # append all values to list using inorder traversal
155+
# append all values to list using inorder traversal
156+
self.inorder(arr, node)
156157
return arr[k - 1]
157158

158159

@@ -162,7 +163,8 @@ def postorder(curr_node):
162163
"""
163164
node_list = list()
164165
if curr_node is not None:
165-
node_list = postorder(curr_node.left) + postorder(curr_node.right) + [curr_node]
166+
node_list = postorder(curr_node.left) + \
167+
postorder(curr_node.right) + [curr_node]
166168
return node_list
167169

168170

@@ -186,36 +188,36 @@ def binary_search_tree():
186188
Traceback (most recent call last):
187189
...
188190
IndexError: Warning: Tree is empty! please use another.
189-
"""
190-
testlist = (8, 3, 6, 1, 10, 14, 13, 4, 7)
191-
t = BinarySearchTree()
192-
for i in testlist:
193-
t.insert(i)
194-
195-
# Prints all the elements of the list in order traversal
196-
print(t)
197-
198-
if t.search(6) is not None:
199-
print("The value 6 exists")
200-
else:
201-
print("The value 6 doesn't exist")
202-
203-
if t.search(-1) is not None:
204-
print("The value -1 exists")
205-
else:
206-
print("The value -1 doesn't exist")
207-
208-
if not t.empty():
209-
print("Max Value: ", t.get_max().value)
210-
print("Min Value: ", t.get_min().value)
211191
212-
for i in testlist:
213-
t.remove(i)
214-
print(t)
192+
>>> t = BinarySearchTree().insert(8, 3, 6, 1, 10, 14, 13, 4, 7)
193+
>>> t.search(6)
194+
{'6': (4, 7)}
195+
>>> t.search(-1)
196+
>>> print(t.root.value)
197+
8
198+
>>> print(t)
199+
{'8': ({'3': (1, {'6': (4, 7)})}, {'10': (None, {'14': (13, None)})})}
200+
>>> t.get_max().value
201+
14
202+
>>> t.get_min().value
203+
1
204+
>>> t.find_kth_smallest(k=2,node=t.root)
205+
3
206+
>>> t.find_kth_smallest(k=5,node=t.root)
207+
7
208+
>>> t.remove(7)
209+
>>> print(" ".join(repr(i.value) for i in t.traversal_tree()))
210+
8 3 1 6 4 10 14 13
211+
>>> t.remove(10)
212+
>>> print(" ".join(repr(i.value) for i in t.traversal_tree()))
213+
8 3 1 6 4 14 13
214+
>>> t.remove(14)
215+
>>> print(" ".join(repr(i.value) for i in t.traversal_tree()))
216+
8 3 1 6 4 13
217+
"""
215218

216219

217220
if __name__ == "__main__":
218221
import doctest
219222

220223
doctest.testmod()
221-
# binary_search_tree()

0 commit comments

Comments
 (0)