#include<stdio.h>
#define MAX 4
int queue[MAX];
int front = -1,rear = -1;
void insert(){
if((rear+1)%MAX != front){
int num;
printf("Enter the Number to be iserted: ");
scanf("%d",&num);
if(front == -1)
{front = 0;}
rear = (rear+1) % MAX;
queue[rear] = num;
}else{
printf("Queue is Full");
}
}
void del(){
if(front == -1){
printf("\nQueue is Empty");
}else{
int num;
num = queue[front];
printf("\nDeleted Number is %d",num);
if(front != rear){
front = (front+1) % MAX;
}else{
front = -1;
rear = -1;
}
}
}
void display(){
if(front == -1){
printf("\nQueue is Empty");
}else{
int i;
for (i = front; i != rear; i = (i + 1) % MAX) {
printf("%d ", queue[i]);
}
printf("%d ", queue[i]);
}
}
void shutdown(){
int i;
for(i = 0;i<=300;i++){
printf("*");
}
printf("\n\n\nShutting down Systumm\n\n\n");
for(i = 0;i<=300;i++){
printf("_");
}
printf("\n\nSystumm off\n\n\n");
}
int main() {
int choice;
printf("\n1. Insert element in the queue");
printf("\n2. Delete element from the queue");
printf("\n3. Display all elements");
printf("\n4. Quit");
do {
printf("\n\nEnter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
insert();
break;
case 2:
del();
break;
case 3:
display();
break;
case 4:
shutdown();
break;
default:
printf("\nInvalid choice");
}
} while (choice != 4);
return 0;
}
Tags:
SY