Question: Programming Language: Python A Queue is an abstract data type for storing a collection of items, where items are added to one end and removed

Programming Language: Python

A "Queue" is an abstract data type for storing a collection of items, where items are added to one end and removed from the opposite end of the collection. The methods for adding and removing items from a queue are traditionally called "enqueue()" and "dequeue()" respectively. IMPORTANT: In this exercise, implementations of both the Stack and Queue ADTs are available to you. You can use the functions Stack(), push(), pop() as well as Queue(), enqueue() and dequeue() as necessary in your function definition. For this exercise, you must write a function called reverse() which is passed a Queue as an input. Your function must modify the Queue, so that the elements in the queue are rearranged into reverse order. HINT: It will be useful to make use of a Stack to help you reverse the elements in the queue.

For example:

Test Result
q1 = Queue() q1.enqueue(1) q1.enqueue(2) q1.enqueue(3) reverse(q1) while not q1.is_empty(): print(q1.dequeue()) 
3 2 1 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!