Question: or this exercise, you will be defining a function which uses the Queue ADT. A Queue ADT implementation is provided to you as part of
or this exercise, you will be defining a function which uses the Queue ADT. A Queue ADT implementation is provided to you as part of this exercise and you can simply use any of the methods:
Queue(), enqueue(), dequeue(), peek(), size() and is_empty()
where necessary inside your function code.
Write the remove_all_occurrences(a_queue, value) function which is passed a Queue object and a value as parameters. Your function must modify the Queue object , so that all the elements in the parameter queue which are the same as the parameter, value. are removed. You may not make use of a Stack object for this question.
For example:
| Test | Result |
|---|---|
a_queue = Queue() remove_all_occurrences(a_queue, 4) print("1: ", end = "") while not a_queue.is_empty(): print(a_queue.dequeue(), end = "") print() | 1: |
a_queue = Queue() a_queue.enqueue('a') a_queue.enqueue('a') a_queue.enqueue('b') a_queue.enqueue('a') remove_all_occurrences(a_queue, 'a') print("2: ", end = "") while not a_queue.is_empty(): print(a_queue.dequeue(), end = "") print() | 2: b |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
