Question: class Queue: def __init__(self): self.__items = [] def is_empty(self): return self.__items == [] def enqueue(self, item): self.__items.insert(0, item) def dequeue(self): return self.__items.pop() def peek(self): return
![class Queue: def __init__(self): self.__items = [] def is_empty(self): return self.__items](https://s3.amazonaws.com/si.experts.images/answers/2024/09/66df73a4cb6e1_16466df73a4583dd.jpg)
class Queue: def __init__(self): self.__items = [] def is_empty(self): return self.__items == [] def enqueue(self, item): self.__items.insert(0, item) def dequeue(self): return self.__items.pop() def peek(self): return self.__items[len(self.__items) - 1] def size(self): return len(self.__items)
Define a function called get_list_by_level (bst) which takes a binary search tree as a parameter. The function should return a Python list containing values in the level-order traversal of the parameter binary search tree (i.e. the function visits every node on a level before going to a lower level). For example, the following binary tree: produces: [64,84,66,32,40,20,55] You may want to use a Queue data structure, where the root node is initially put into the queue, and then the queue is processed as follows: - While the queue is not empty - Remove the front element of the queue - Append the value into the result list - Enqueue the left child into the queue if it is not None - Enqueue the right child into the queue if it is not None Note: You can assume that the parameter binary search tree is not empty. IMPORTANT: For this exercise, you will be defining a function which USES the BinarySearchTree ADT and the Queue ADT. Both implementations are provided to you as part of this exercise - you should not define them in your answer. Instead, your code can make use of any of the BinarySearchTree/Queue ADT fields and methods. For example
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
