Program :
#include<stdio.h>
#include<conio.h>
# define MAX 5
int a[MAX],front=-1,rear=-1;
int display()
{
int i;
if(front==-1&&rear==-1)
{
printf("\nEmpty queue") ;
return 0;
}
printf("\nQueue elements:: ");
for(i=front;a[i]!=0;i++)
{
printf("%d\t",a[i]);
}
return 1;
}
int insert()
{
int num,i;
if(rear==MAX-1)
{
printf("\n\tOVERFLOW!") ;
return 0;
}
printf("\nEnter the number :\t");
scanf("%d",&num);
for(i=front;a[i]!=0;i++)
{
if(a[i]==num)
{
printf("Number already exist");
return 0;
}
}
if (front==-1&&rear==-1)
{
front=0;
rear=0;
}
else
rear=rear+1;
a[rear]=num;
display();
return 1;
}
int del()
{
if(front==-1)
{
printf("UNDERFLOW!");
return 0;
}
printf("Element deleted: %d",a[front]);
a[front]=0;
if(front==rear)
{
front=-1;
rear=-1;
}
else
front=front+1;
display();
return 1;
}
void main()
{
int opt;
clrscr();
while(1)
{
printf("\nChoose the queue operation\n1.INSERTION\n2.DELETION\n3.EXIT");
scanf("%d",&opt);
switch(opt)
{
case 1:insert();break;
case 2:del();break;
case 3:exit(0);
default:printf("INVALID OPTION");break;
}
}
}
#include<stdio.h>
#include<conio.h>
# define MAX 5
int a[MAX],front=-1,rear=-1;
int display()
{
int i;
if(front==-1&&rear==-1)
{
printf("\nEmpty queue") ;
return 0;
}
printf("\nQueue elements:: ");
for(i=front;a[i]!=0;i++)
{
printf("%d\t",a[i]);
}
return 1;
}
int insert()
{
int num,i;
if(rear==MAX-1)
{
printf("\n\tOVERFLOW!") ;
return 0;
}
printf("\nEnter the number :\t");
scanf("%d",&num);
for(i=front;a[i]!=0;i++)
{
if(a[i]==num)
{
printf("Number already exist");
return 0;
}
}
if (front==-1&&rear==-1)
{
front=0;
rear=0;
}
else
rear=rear+1;
a[rear]=num;
display();
return 1;
}
int del()
{
if(front==-1)
{
printf("UNDERFLOW!");
return 0;
}
printf("Element deleted: %d",a[front]);
a[front]=0;
if(front==rear)
{
front=-1;
rear=-1;
}
else
front=front+1;
display();
return 1;
}
void main()
{
int opt;
clrscr();
while(1)
{
printf("\nChoose the queue operation\n1.INSERTION\n2.DELETION\n3.EXIT");
scanf("%d",&opt);
switch(opt)
{
case 1:insert();break;
case 2:del();break;
case 3:exit(0);
default:printf("INVALID OPTION");break;
}
}
}