Question: Write the functions in python, include screenshot and explanations for the functions please Define the functions using both the Stack and Queue ADTs. You must
Write the functions in python, include screenshot and explanations for the functions please
Define the functions using both the Stack and Queue ADTs. You must make use of any of the Queue ADT methods: Queue(), enqueue(), dequeue(), peek(), size() and is_empty() You must also make use of any of the Stack ADT methods: Stack(), push(), pop(), peek(), size() and is_empty(). Write a function called mirror_queue(a_queue) which takes a Queue as a parameter. The function must modify the parameter Queue object so that the original queue items appear in their original order followed by a copy of the queue items in reverse order.
HINT: It will be useful to make use of a Stack and another Queue to help you mirror the elements in the queue.
| Test | Result |
q1 = Queue() q1.enqueue(1) q1.enqueue(2) q1.enqueue(3) print(q1) mirror_queue(q1) print(q1) | Queue: Front [1, 2, 3] Rear Queue: Front [1, 2, 3, 3, 2, 1] Rear |
q1 = Queue() q1.enqueue(1) q1.enqueue(2) q1.enqueue(3) q1.enqueue(4) q1.enqueue(5) print(q1) mirror_queue(q1) print(q1) | Queue: Front [1, 2, 3, 4, 5] Rear Queue: Front [1, 2, 3, 4, 5, 5, 4, 3, 2, 1] Rear |
q1 = Queue() mirror_queue(q1) print(q1) | Queue: Front [] Rear |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
