Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Queue:
- def __init__(self, Size):
- self.Size = Size
- self.QueueLis = [None]*self.Size
- self.Front = 0
- self.Rear = 0
- self.Count = 0
- def Push(self, Val):
- if(self.Count < self.Size):
- self.QueueLis[self.Rear % self.Size] = Val
- self.Rear += 1
- self.Count += 1
- else:
- print("Queue Is Full")
- def Top(self):
- print(self.QueueLis[self.Front % self.Size])
- def Pop(self):
- self.Count -= 1
- self.QueueLis[self.Front % self.Size] = None
- self.Front += 1
- def PrintQueue(self):
- print(self.QueueLis)
- ObjQueue = Queue(5)
- ObjQueue.Push(1)
- ObjQueue.Push(2)
- ObjQueue.Push(3)
- ObjQueue.Push(4)
- ObjQueue.Push(5)
- ObjQueue.PrintQueue()
- ObjQueue.Push(6)
- ObjQueue.Top() # 1
- ObjQueue.Pop() # Pop 1
- ObjQueue.PrintQueue()
- ObjQueue.Top() # 2
- ObjQueue.Push(6)
- ObjQueue.Pop() # Pop 2
- ObjQueue.PrintQueue()
- ObjQueue.Top() # 3
- ObjQueue.Push(7)
- ObjQueue.PrintQueue()
- ObjQueue.Pop() # Pop 3
- ObjQueue.Push(8)
- ObjQueue.Pop()
- ObjQueue.Push(9)
- ObjQueue.PrintQueue()
- #ObjQueue.Pop()
- ObjQueue.Top()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement