Python Q question

Asked 2 years ago, Updated 2 years ago, 139 views

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

python queue

2022-09-21 21:06

1 Answers

Fix the last isFull like this.

def isFull(self):
    if self.max_size <= self.rear:
        return True
    else:
        return False


2022-09-21 21:06

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.