赞
踩
class MyCircularQueue: def __init__(self, k: int): self.size=k+1 self.rear=0 self.front=0 self.queue=[None for _ in range(k+1)] def enQueue(self, value: int) -> bool: if self.front==(self.rear+1)%self.size: return False self.rear=(self.rear+1)% self.size self.queue[self.rear]=value return True def deQueue(self) -> bool: if self.front==self.rear: return False self.queue[self.front]=None self.front=(self.front+1)% self.size return True def Front(self) -> int: if self.front==self.rear: return -1 return self.queue[(self.front+1)%self.size] def Rear(self) -> int: if self.front==self.rear: return -1 return self.queue[self.rear] def isEmpty(self) -> bool: if self.front==self.rear: return True return False def isFull(self) -> bool: if self.front==(self.rear+1)%self.size: return True return False # Your MyCircularQueue object will be instantiated and called as such: # obj = MyCircularQueue(k) # param_1 = obj.enQueue(value) # param_2 = obj.deQueue() # param_3 = obj.Front() # param_4 = obj.Rear() # param_5 = obj.isEmpty() # param_6 = obj.isFull()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。