Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Differentiate 3sin(9x+2x)

Answered: 1 week ago

Question

Compute the derivative f(x)=(x-a)(x-b)

Answered: 1 week ago

Question

Does it have at least one-inch margins?

Answered: 1 week ago

Question

Does it highlight your accomplishments rather than your duties?

Answered: 1 week ago