Queue in C : Working of queue on the basis of first-in-first-out (FIFO) data structure.
Queue Real Life of Example
https://www.sitesbay.com/cpp-datastructure/cpp-queue-program-example
Ticket Counter : First person get ticket first and go out first.
1. Queue in C
Queue is also an abstract data type or a linear data structure, in which the first element is inserted from
one end called REAR(also called tail), and the deletion of existing element takes place from the other
end called as FRONT(also called head). Here we learn about Queue in C
Working of queue on the basis of first-in-first-out (FIFO) data structure.
Queue Real Life Example
A real-world example of queue can be a single-lane one-way road, where the vehicle enters first, exits
first. More real-world examples can be seen as queues at the ticket windows and bus-stops.
Ticket Counter : First person get ticket first and go out first.
2. Some other Real Life Examples of Queue are;
Queue of people at any service point such as ticketing etc.
Queue of processes in OS.
Queue of packets in data communication.
Queue of air planes waiting for landing instructions.
Example of Queue
#include<conio.h>
#include<stdio.h>
#define N 6
int queue[N]={0};
int rear=0,front=0;
void insert(void);
void del(void);
void disp(void);
void cre(void);
void main()
{
int user=0;
clrscr();
while(user!=4)
{
clrscr();
printf("nnnttt THE SIZE OF QUEUE IS %d",N);
3. printf("nt 1.INSERT");
printf("nt 2.DELETE");
printf("nt 3.DISPLAY");
printf("nt 4.EXIT");
printf("nt 5.CREATE");
scanf("%d",&user);
switch(user)
{
case 1:
insert();
break;
case 2:
del();
break;
case 3:
disp();
break;
case 4:
printf("nt THANK U");
break;
case 5:
cre();
break;
}
getch();
}
getch();
}
4. /********************* Insert Value in Queue ********************/
void insert(void)
{
int t;
if(rear<N)
{
printf("nt ENTER A VALUE IN QUEUE");
scanf("%d",&t);
queue[rear]=t;
rear++;
}
else
{
printf("nt Q OVERFLOW!!!!!!!!!!!!!!!");
}
}
void del(void)
{
int i;
printf("nt %d gets deleted.........",queue[front]);
queue[front]=0;
front++;
}
void disp(void)
{
int i;
for(i=front;i<rear;i++)
{
printf("nt %d",queue[i]);