0% found this document useful (0 votes)
34 views3 pages

Insert Del Display Main: MAX 3 1 1 MAX

This C program implements a circular queue using an array. It defines functions for insertion, deletion, and displaying elements in the queue. The main function contains a menu loop that calls the respective functions based on user input and allows exiting the program. The insert function adds elements to the rear of the queue, delete removes elements from the front, and display prints all current elements.

Uploaded by

Kanabi Raj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views3 pages

Insert Del Display Main: MAX 3 1 1 MAX

This C program implements a circular queue using an array. It defines functions for insertion, deletion, and displaying elements in the queue. The main function contains a menu loop that calls the respective functions based on user input and allows exiting the program. The insert function adds elements to the rear of the queue, delete removes elements from the front, and display prints all current elements.

Uploaded by

Kanabi Raj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

#include<stdio.

h>
#define MAX 3
int front = -1, rear = -1;
int cq[MAX];
void insert();
void del();
void display();
int main()
{
int ch;
while(1)
{
printf("1.Insert\n2.Delete\n3.Display\n4.Exit");
printf("\nEnter Your Choice :- ");
scanf("%d",&ch);
switch(ch)
{
case 1:
insert();
break;
case 2:
del();
break;
case 3:
display();
break;
case 4:
exit(0);
break;
}
}
return 0;
}
void insert()
{
int val;
if((rear==MAX-1 && front==0) || (rear+1==front))
{
printf("Queue Is Full\n");
}
else
{
if(front==-1)
{
front=0;
}
if(rear==MAX-1)
{
rear=0;
}
else
{
rear++;
}
printf("Enter Elelement :- ");
scanf("%d",&val);
cq[rear]=val;
}
}
void del()
{
int item;
if(front == -1 & rear == -1)
{
printf("\nUNDERFLOW\n");
return;
}
else if(front == rear)
{
item=cq[front];
front = -1;
rear = -1;
}
else if(front == MAX -1)
{
item=cq[front];
front = 0;
}
else
{
item=cq[front];
front = front + 1;
}
printf("Deleted Item Is %d\n",item);
}
void display()
{
int i;
if(front==-1)
{
printf("Queue Is Underflow\n");
}
else
{
printf("Queue Element Are Front -> ");
if(front<=rear)
{
for(i=front; i<=rear; i++)
{
printf("%d\t",cq[i]);
}
}
else
{
for(i=front; i<=MAX-1; i++)
{
printf("%d\t",cq[i]);
}
for(i=0; i<=rear; i++)
{
printf("%d\t",cq[i]);
}
}
printf("<- Rear\n");
}
}

You might also like