Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
PyWeekD
#python 3.6.9 ###################################### #PyWeekD: application of Circular Queue in Python #this code is created by Rezaul Hoque on August 31,2022; #contact:jewelmrh@yahoo.com;Dhaka,Bangladesh;https://rezaulhoque.wordpress.com,https://hoquestake.blogspot.com #note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; ###################################### class WeekD(): def __init__ (self,s): self.s=s @property def getS(self): return f"{self.s}" class CirQueue(): def __init__(self, sz): self.sz = sz self.queue = [None] * sz self.first = self.last = -1 def enqueue(self, x): if ((self.last + 1) % self.sz== self.first): print("The circular queue is full\n") elif (self.first== -1): self.first = 0 self.last= 0 self.queue[self.last] = x else: self.last = (self.last+ 1) % self.sz self.queue[self.last] = x def dequeue(self): if (self.first == -1): print("The circular queue is empty\n") elif (self.first== self.last): temp = self.queue[self.first] self.first = -1 self.last= -1 return temp else: temp = self.queue[self.first] self.first= (self.first + 1) % self.sz return temp sat=WeekD("Saturday: Do some house cleaning!\n"); sun=WeekD("Sunday: Relax,Eat,Sleep,Read,Repeat!\n"); mon=WeekD("Monday: Code,Code and Code!\n"); tue=WeekD("Tuesday: Walk,Walk and Walk!\n"); wed=WeekD("Wednesday: Attend the invitation!\n"); obj = CirQueue(5) obj.enqueue(sat) obj.enqueue(sun) obj.enqueue(mon) obj.enqueue(tue) obj.enqueue(wed) print("Agendas For The Week") for i in range (obj.first,obj.last+1): print(f" {obj.queue[i].getS}",end="\n")
run
|
edit
|
history
|
help
0
queue and stack
wordchangething
Add missing names
max area rectangle
Breadth-First Path Finding
PyRegLookBehind
PyEq
134
камень ножницы бумага
pico menu