Professional Documents
Culture Documents
• This data structure has two ends viz. Front and Rear.
• Data added to the queue from the last called REAR.
• Data removed from the beginning end called FRONT.
FRONT- the index where the first element is stored in the array
representing the queue.
• Peek - To access the first element of the queue without removing it.
You should take the following steps to remove data from the queue -
Used to get the element at the front of the queue without removing it.
This function helps in extracting the data element where the front is
pointing without removing it from the queue.
Step 1: Check if the rear and front are pointing to null memory space,
i.e., -1.
Step 2: If they are pointing to -1, return “Queue is empty.”
Step 3: If they are not equal, return “Queue is not empty.”
Circular Queue
A circular queue is a special case of a simple queue in which the last
member is linked to the first.
As a result, a circle-like structure is formed.
If elements with the same priority occur, they are served according to
their order in the queue.
Insertion occurs based on the arrival of the values and removal occurs
based on priority.
#include<stdio.h>
#define n 5
int main()
{
int queue[n],ch=1,front=0,rear=0, i, j=1, x=n;
printf("Queue using Array");
printf("\n1.Insertion \n2.Deletion \n3.Display \n4.Exit");
while(ch)
{
printf("\nEnter the Choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
if(rear==x)
printf("\n Queue is Full");
else
{
printf("\n Enter no %d:",j++);
scanf("%d",&queue[rear++]);
}
break;
case 2:
if(front==rear)
{
printf("\n Queue is empty");
}
else
{
printf("\n Deleted Element is %d",queue[front++]);
x++;
}
break;
case 3:
printf("\nQueue Elements are:\n ");
if(front==rear)
printf("\n Queue is Empty");
else
{
for(i=front; i<rear; i++)
{
printf("%d",queue[i]);
printf("\n");
}
break;
case 4:
exit(0);
default:
printf("Wrong Choice: please see the options");
}
}
}
return 0;
}
Output :Queue using Array
1.Insertion
2.Deletion
3.Display
4.Exit
Enter the Choice:1
Enter no 1:10
Enter no 2:54
Enter no 3:98
Enter no 4:234
• Printers: Queue data structure is used in printers to maintain the order of pages
while printing.
• Interrupt handling in computes: The interrupts are operated in the same order
as they arrive, i.e., interrupt which comes first, will be dealt with first.
• Switches and Routers: Both switch and router interfaces maintain ingress
(inbound) and egress (outbound) queues to store packets.
• Customer service systems: It develops call center phone systems using the
concepts of queues.
• Managing requests on a single shared resource such as CPU scheduling and
disk scheduling