How do I implement a function or method that allows me to specify the maximum size of the queue here?
class MyQueue: def init(self, max_size): self.myList=[] self.max_size=max_size self.front=-1 self.rear=0
def enqueue(self, item):
if self.isFull():
return
else:
self.myList.append(item)
self.rear=self.rear+1
def dequeue(self):
if self.isEmpty():
return None
else:
self.rear=self.rear-1
return self.myList.pop(0)
def isEmpty(self):
if self.rear>0:
return False
else:
return True
def isFull(self):
if self.size <= self.rear:
return True
else:
return False
Fix the last isFull
like this.
def isFull(self):
if self.max_size <= self.rear:
return True
else:
return False
© 2024 OneMinuteCode. All rights reserved.