Queue in C, Queue Real Life of Example

6,916 views 5 slides Nov 03, 2016
Slide 1
Slide 1 of 5
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5

About This Presentation

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.


Slide Content

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.

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("\n\n\n\t\t\t THE SIZE OF QUEUE IS %d",N);

printf("\n\t 1.INSERT");
printf("\n\t 2.DELETE");
printf("\n\t 3.DISPLAY");
printf("\n\t 4.EXIT");
printf("\n\t 5.CREATE");
scanf("%d",&user);
switch(user)
{
case 1:
insert();
break;
case 2:
del();
break;
case 3:
disp();
break;
case 4:
printf("\n\t THANK U");
break;
case 5:
cre();
break;
}
getch();

}
getch();
}

/********************* Insert Value in Queue ********************/
void insert(void)
{
int t;
if(rear<N)
{
printf("\n\t ENTER A VALUE IN QUEUE");
scanf("%d",&t);
queue[rear]=t;
rear++;
}
else
{
printf("\n\t Q OVERFLOW!!!!!!!!!!!!!!!");
}
}
void del(void)
{
int i;
printf("\n\t %d gets deleted.........",queue[front]);
queue[front]=0;
front++;
}
void disp(void)
{
int i;
for(i=front;i<rear;i++)
{
printf("\n\t %d",queue[i]);

}
}
void cre(void)
{

int t;
printf("\n\t ENTER A VALUE IN QUEUE");
scanf("%d",&t);
front=0;
queue[front]=t;
rear=front+1;
}