641 Design circular queue

class MyCircularQueue:def __init__(self, k: int):
self.size, self.front,self.rear =0,0,-1
self.capacity =k
self.arr=[None for i in range(k)]
def enQueue(self, value: int) -> bool:
if self.isFull():
return False
self.rear=self.rear+1
self.rear=self.rear%self.capacity
self.arr[self.rear]=value
self.size+=1
return True
def deQueue(self) -> bool:
if self.isEmpty():
return False

self.front=self.front+1
self.front=self.front%self.capacity

self.size-=1
return True
def Front(self) -> int:
if self.isEmpty():
return -1
return self.arr[self.front]
def Rear(self) -> int:
if self.isEmpty():
return -1
return self.arr[self.rear]
def isEmpty(self) -> bool:
if self.size ==0:
return True
return False
def isFull(self) -> bool:
if self.size ==self.capacity:
return True
return False

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Dhanarajappu

Dhanarajappu

Tech-Enthusiast, Coder,Explorer,Geeky,Software Engineer |A piece of code delivers everything that you need. The world is all about codes.