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

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 Physics Questions!