Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

pls answer in version 3 of python Implement the Queue ADT using a Python list -

ID: 3748204 • Letter: P

Question

pls answer in version 3 of python

Implement the Queue ADT using a Python list - map the front of the queue to the rear of the list and the back of the queue to the front of the list as discussed in lectures. You should implement the following queue methods: init enqueue dequeue peek is_empty size str For example: Test Result carBrandQueue) carlist 'Audi', ' fori in range(len(carlist)): Mercedes Toyota Honda Audi Honda", 'Toyota', "Mercedes'"] carBrand.enqueue(carlist i].) print(carBrand) card = Queue() cardlist -C'AS, 'AH', 'AC, 'AD, '25', "2H', '2C, '2D'] for i in range(len(cardlist)): 2D 2C 2H 2S AD AC AH AS card. enqueue(cardlistli]) print(card)

Explanation / Answer

# cook your dish here
from collections import deque

class Queue:

#Constructor creates a list
def __init__(self):
self.queue = list()

#Adding elements to queue
def enqueue(self,data):
#Checking to avoid duplicate entry (not mandatory)
if data not in self.queue:
self.queue.insert(0,data)
return True
return False

#Removing the last element from the queue
def dequeue(self):
if len(self.queue)>0:
return self.queue.pop()
return ("Queue Empty!")
  
#checking if queue is Empty
def isEmpty(self):
if len(self.queue)>0:
return ("Queue not Empty!")

#Getting the size of the queue
def size(self):
return len(self.queue)

#printing the elements of the queue
def printQueue(self):
return self.queue

carBrand = Queue()
carlist = ['Audi','Honda','Toyota','Marcedes']
for i in range(len(carlist)):
carBrand.enqueue(carlist[i])
for i in range(len(carlist)):   
print(carBrand.dequeue())