Question: HELP Data Structures: Modify the python code to remove an item in a list and then move it to the back of a queue in
HELP Data Structures: Modify the python code to remove an item in a list and then move it to the back of a "queue" in that list



q.isEmpty()
q.addFront (100)
print(q.size())
q.addFront (200)
q.addFront (500.58)
print(q.size())
print(q.peek()) # print the front item of the queue
q.addRear(500)
q.addRear(600)
q.addFront(3.14)
print(q.size())
print(q.peek()) # print the front item of the queue
q.removeFront()
print(q.size())
print(q.peek()) # print the front item of the queue
q.addRear(True)
q.addRear(False)
print(q.size())
q.isEmpty()
q.addRear(8.4)
q.removeRear()
print(q.size())
print(q.peek()) # print the front item of the queue
q.addRear(C++)
q.addRear(Python)
q.addRear(Java)
print(q.size())
q.addFront (Go)
q.addFront (C)
print(q.size())
print(q.dequeue())
q.removeFront()
q.removeFront()
print (q.size())

class Queue(): # CircularArrayQueue.py DAS modified from Goodrich 93
def __init__(self):
self.items = [None] * 10
self.size = 0
self.front = 0
def size(self):
return self.size
def is_empty(self):
return self.size == 0
def first(self):
if self.is_empty():
raise Empty('Queue is empty')
return self.items[self.front]
def enqueue(self, item):
if self.size == len(self.items):
self.resize(2 * len(self.items))
avail = (self.front + self.size) % len(self.items)
self.items[avail] = item
self.size += 1
def dequeue(self):
if self.is_empty():
raise Empty('Queue is empty')
answer = self.items[self.front]
self.items[self.front] = None
self.front = (self.front + 1) % len(self.items)
self.size = 1
return answer
def resize(self, cap):
old = self.items
self.items = [None] * cap
walk = self.front
for k in range(self.size):
self.items[k] = old[walk]
walk = (1 + walk) % len(old)
self.front = 0
#### Don't necessarily need these below
S = Queue()
print("Entering two elements (5, then 3) into the queue ...")
S.enqueue(5)
S.enqueue(3)
print()
print("It is not intended that the client (root or main in this case) ")
print("have access to the underlying data array; nonetheless, it is: ")
print("front index:%i queue size:%i available storage:%i"%(S.front,S.size,len(S.items)))
print(S.items,' ')
print()
print("Removing element from queue .... ")
capture = S.dequeue()
print()
print("The underlying data array again: ")
print("front index:%i queue size:%i available storage:%i"%(S.front,S.size,len(S.items))) print(S.items)
print()
print("Inserting eight more elements (101 eight times) into the array... ")
for i in range(8):
S.enqueue(101)
print()
print("The underlying data array again: ")
print("front index:%i queue size:%i available storage:%i"%(S.front,S.size,len(S.items)))
print(S.items)
print()
print("Inserting one more element (202) into the array... ")
S.enqueue(202)
print()
print("The underlying data array again: ")
print("front index:%i queue size:%i available storage:%i"%(S.front,S.size,len(S.items)))
print(S.items)
print()
print("Inserting one more element (205) into the array... ")
S.enqueue(205)
print("the underlying data array again...")
print("front index:%i queue size:%i available storage:%i"%(S.front,S.size,len(S.items)))
print(S.items)
The task is to extend/modify the ArrayQueue code so that the result is a circular array implementation of a double-ended-queue (deque pronounced "deck"). Function naming/renaming should be consistent with the documentation below
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
