Python: Using the Self Parameter
Reverse a Queue using a Stack
Steps:
1. Have the user enter 5 numbers and place them in a queue.
2. Print the queue.
3. Dequeue the elements from the Queue and push them into a Stack until the Queue becomes empty.
4. Pop the elements from the Stack and enqueue them to the Queue until the stack is empty. As a result, the elements in the Queue will be reversed.
5. Print the queue.
How to print a queue without iterating through a list:
To print your queue, add the following method to your queue class:
def display(self):
print(self.queue)