program1
class CircularQueue:
def init(self, max_size=10):
self.max_size = max_size
self.queue = [None] * max_size
self.front = -1
self.rear = -1
def is_full(self):
return (self.rear + 1) % self.max_size == self.front
def is_empty(self):
return self.front == -1
def insert(self, item):
if self.is_full():
print("Queue Overflow")
return
if self.front == -1:
self.front = 0
self.rear = (self.rear + 1) % self.max_size
self.queue[self.rear] = item
def delete(self):
if self.is_empty():
print("Queue Underflow")
return
deleted_item = self.queue[self.front]
if self.front == self.rear:
self.front = -1
self.rear = -1
else:
self.front = (self.front + 1) % self.max_size
print(f"Element deleted from queue is: {deleted_item}")
def display(self):
if self.is_empty():
print("Queue is empty")
return
print("Queue elements:", end=" ")
i = self.front
while True:
print(self.queue[i], end=" ")
if i == self.rear:
break
i = (i + 1) % self.max_size
print()
def main():
circular_queue = CircularQueue()
while True:
choice = input().strip()
if choice.startswith("1"):
_, item = choice.split()
circular_queue.insert(int(item))
elif choice == "2":
circular_queue.delete()
elif choice == "3":
circular_queue.display()
elif choice == "4":
break
else:
print("Wrong choice")
if name == "main":
main()