File tree Expand file tree Collapse file tree
datastructures/trees/binary/search_tree Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -406,6 +406,7 @@ def breadth_first_search(self) -> List[Any]:
406406 Performs a breadth first search through a Binary Tree
407407 This will traverse the tree level by level and depth by depth. Using a Queue to put elements into the queue
408408 """
409+ result = []
409410 queue = FifoQueue ()
410411
411412 # start off by adding the root node
@@ -414,13 +415,16 @@ def breadth_first_search(self) -> List[Any]:
414415 # while the queue is not empty, we want to traverse the tree and add elements to the queue,
415416 while not queue .is_empty ():
416417 current_node = queue .dequeue ()
418+ result .append (current_node .data )
417419
418420 if current_node .left :
419421 queue .enqueue (current_node .left )
420422
421423 if current_node .right :
422424 queue .enqueue (current_node .right )
423425
426+ return result
427+
424428 def pre_order (self ) -> List [Any ]:
425429 """
426430 Type of Depth First Traversal (DFS) for binary trees which will start at root node and proceed to the left
You can’t perform that action at this time.
0 commit comments