Question
In Python Language, help me to implement the given code into a function named reverse_queue in Queue.py that reverses the order of the given queue.
In Python Language, help me to implement the given code into a function named reverse_queue in Queue.py that reverses the order of the given queue. Use dequeue and enqueue to remove the last item from the original list and add it to the new list. Then, save the new, reversed order to the original variable.
class Queue:
def __init__(self):
self._items = []
def insert(self, item):
self._items = [item] + self._items
def remove(self):
last = self._items[-1]
self._items = self._items[:-1]
return last
def peek(self):
return self._items[-1]
def is_empty(self):
return len(self._items) == 0
def size(self):
return len(self._items)
def __str__(self):
return str(self._items)
def main():
queue1 = Queue()
queue1.is_empty()
queue1.insert('Code')
queue1.insert('Python')
queue1.insert('Reverse')
queue1.insert('computer') queue1.insert('science')
print(queue1)
print(queue1.remove())
queue1.is_empty()
queue1.size()
print(queue1.peek())
main()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started