Skip to content

Commit 92b7060

Browse files
authored
Update binary_search_tree.py
1 parent 98a5a16 commit 92b7060

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

data_structures/binary_tree/binary_search_tree.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,8 @@
8888
>>> not t
8989
True
9090
"""
91-
9291
from __future__ import annotations
93-
92+
from pprint import pformat # Moved to top-level
9493
from collections.abc import Iterable, Iterator
9594
from dataclasses import dataclass
9695
from typing import Any, Self
@@ -115,8 +114,6 @@ def __iter__(self) -> Iterator[int]:
115114
yield from self.right or []
116115

117116
def __repr__(self) -> str:
118-
from pprint import pformat
119-
120117
if self.left is None and self.right is None:
121118
return str(self.value)
122119
return pformat({f"{self.value}": (self.left, self.right)}, indent=1)
@@ -196,12 +193,11 @@ def insert(self, *values) -> Self:
196193
for value in values:
197194
self.__insert(value)
198195
return self
199-
200-
def search(self, value) -> Node | None:
196+
def search(self, value) -> Node | None:
201197
"""
202198
>>> tree = BinarySearchTree().insert(10, 20, 30, 40, 50)
203199
>>> tree.search(10)
204-
{'10': (None, {'20': (None, {'30': (None, {'40': (None, 50)})})})}
200+
{'10': (None, {'20': (None, {'30': (None, {'40': (None, 50)})})}
205201
>>> tree.search(20)
206202
{'20': (None, {'30': (None, {'40': (None, 50)})})}
207203
>>> tree.search(30)
@@ -314,8 +310,7 @@ def traversal_tree(self, traversal_function=None) -> Any:
314310
return self.preorder_traverse(self.root)
315311
else:
316312
return traversal_function(self.root)
317-
318-
def inorder(self, arr: list, node: Node | None) -> None:
313+
def inorder(self, arr: list, node: Node | None) -> None:
319314
"""Perform an inorder traversal and append values of the nodes to
320315
a list named arr"""
321316
if node:

0 commit comments

Comments
 (0)