Insert Del Display Main: MAX 3 1 1 MAX

Download as pdf or txt
Download as pdf or txt
You are on page 1of 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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy