We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 93ead3b commit 7862cc3Copy full SHA for 7862cc3
search/binary_search_tree.py
@@ -5,18 +5,20 @@ def __init__(self, value):
5
self.right = None
6
7
def depth_first_for_each(self, cb):
8
+ s = Queue()
9
+ s.enqueue(self.value)
10
+
11
def rec(current_node):
12
+ cb(s.dequeue())
13
if current_node.left is None and current_node.right is None:
- return current_node.value
- if current_node.left is not None:
- cb(current_node.left.value)
- if current_node.right is not None:
14
- cb(current_node.right.value)
15
-
+ return
16
if current_node.left is not None:
+ s.enqueue(current_node.left.value)
17
rec(current_node.left)
18
if current_node.right is not None:
19
+ s.enqueue(current_node.right.value)
20
rec(current_node.right)
21
22
rec(self)
23
24
def breadth_first_for_each(self, cb):
0 commit comments