//this code is designed by codenation.
//4:30 13/12/2020
#include<stdio.h>
int qinsert(int queue[]);
int qdelete(int queue[]);
int n;
int queue[1];
int front=-1;
int rear=-1;
int flag=0;
int main()
{
int ch,i;
printf("enter the size of queue :\n");
scanf("%d",&n);
int queue[n];
while(1)
{
printf("enter your choice :\n");
printf("1.INSERT(ENQUEUE)\n2.DELETE(DEQUEUE)\n3.VIEW QUEUE\n4.EXIT\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
qinsert(queue);
break;
case 2:
qdelete(queue);
break;
case 3:
if(front==-1 || rear==-1 )
{
printf("\nTHE QUEUE IS EMPTY!\n\n");
break;
}
if(flag==1)
{
printf("\nTHE QUEUE IS :\n");
for(i=rear;i<n;i++)
{
printf("%d\n",queue[i]);
}
printf("\n");
}
else if(flag==0)
{
printf("\nTHE QUEUE IS :\n");
for(i=front;i<=rear;i++)
{
printf("%d\n",queue[i]);
}
printf("\n");
}
break;
case 4:
return 0;
}
}
}
int qinsert(int queue[])
{
int item;
if((front==0 && rear==n-1) || rear==front-1)
{
printf("\nQUEUE OVERFLOW!!!\n\n");
return 0;
}
printf("enter the item to be inserted in queue :\n");
scanf("%d",&item);
if(front==-1)
{
front=0;
rear=0;
}
else if(rear==n-1)
{
rear=0;
flag=1;
}
else
{
rear=rear+1;
}
queue[rear]=item;
printf("\nELEMENT INSERTED SUCCESSFULLY....\n\n");
return 0;
}
int qdelete(int queue[])
{
int val;
if(front==-1)
{
printf("\nQUEUE UNDERFLOW!!!\n\n");
return 0;
}
val=queue[front];
if(front==rear)
{
front=-1;
rear=-1;
}
else if(front==n-1)
{
front=0;
flag=0;
}
else
{
front=front+1;
}
printf("\n%d IS REMOVED FROM QUEUE SUCCESSFULLY....\n\n",val);
return 0;
}
//this code is developed by codenation.
Comments
Post a Comment