Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Fundamentals Of Database Systems

Authors: Sham Navathe,Ramez Elmasri

5th Edition

B01FGJTE0Q, 978-0805317558

More Books

Students also viewed these Databases questions