Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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_2

Step: 3

blur-text-image_3

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

College Physics

Authors: Raymond A. Serway, Jerry S. Faughn, Chris Vuille, Charles A. Bennett

7th Edition

9780534997236, 495113697, 534997236, 978-0495113690

More Books

Students also viewed these Physics questions

Question

6. What does the invisible hand of the marketplace do?

Answered: 1 week ago