//this code is designed by codenation.
//3:30 12/12/2020
#include<stdio.h>
#include<stdlib.h>
int enqueue(int queue[]);
int dequeue(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 an 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:
enqueue(queue);
break;
case 2:
dequeue(queue);
break;
case 3:
if(front==-1 || rear==-1 || flag==1)
{
printf("\nTHE QUEUE IS EMPTY!\n\n");
break;
}
printf("\nTHE QUEUE IS :\n");
for(i=front;i<=rear;i++)
{
printf("%d\n",queue[i]);
}
printf("\n");
break;
case 4:
exit(0);
}
}
}
int enqueue(int queue[])
{
int item;
if(rear==n-1)
{
printf("\nQUEUE OVERFLOW!!!\n\n");
return 0;
}
if(front==-1 || rear==-1)
{
front=0;
rear=0;
}
else
{
rear=rear+1;
}
printf("enter the item to be inserted in queue :\n");
scanf("%d",&item);
queue[rear]=item;
printf("\nELEMENT INSERTED SUCCESSFULLY....\n\n");
return 0;
}
int dequeue(int queue[])
{
int val;
if(front==-1)
{
printf("\nQUEUE UNDERFLOW!!!\n\n");
return 0;
}
val=queue[front];
front=front+1;
if(front==n)
{
flag=1;
}
printf("\n%d IS REMOVED FROM QUEUE SUCCESSFULLY....\n\n",val);
return 0;
}
//this code is developed by codenation.
Comments
Post a Comment