DATA STRUCTURES



Admission Enquiry Form

Queue Data Structure

It is a linear data structure in which elements are arranged in First In First Out (FIFO) order. A queue enables insert operations to be performed at one end called REAR and delete operations to be performed at another end called FRONT.

Operations performed in Queue.

insertion()/enqueue()

deletion()/dequeue()

 

Queue data structure

queue-data-structure-by-compuhelp

Insertion/Enqueue operation in Queue

Enqueue operation means to insert an element in the queue


Algorithm of Enqueue operation in Stack

Enqueue Algorithm
Step 1: START
Step 2: REAR : = 0, FRONT : =1[initialize REAR to 0 and FRONT to 1]
Step 3: If Rear=MAXSIZE-1
Write “Overflow: Queue is full” and Exit
[End of If]
Step 4: REAR :=REAR+1
Step 5: Queue [REAR] :=ITEM
Step 6: End



Deletion/Dequeue operation in Queue

Dequeue operation means to delete an element from the queue



Algorithm of Dequeue operation in Stack

Step 1: START
Step 2: If REAR: = 0
Write “Underflow: Queue is empty” and Exit
[End of if]
Step 3: ITEM:=Queue [FRONT]  [ITEM contains the deleted element]
Step 4: If FRONT=REAR
Set REAR: =0 and FRONT : = 1
Else
FRONT=FRONT+1
[End of If Else]
Step 5: Return ITEM
Step 6: End





Program of Queue Operation

#include<stdio.h>
int queue[100],size=100,front=0,rear=-1;
void Insert(int val)
{
if(rear==size-1)
printf("Overflow: Queue is full \n");
else
{
rear++;
queue[rear]=val;
}

}

void Delete()
{
if(rear==-1 || front>rear)
{
printf("Queue Underflow \n");
}
else
{
printf("The deleted element = %d ",queue[front]);
front++;
}
}

void Show()
{
if(front==-1)
printf("Queue is empty\n");
else
{
printf("Queue Element are");
for(int i=front;i<=rear;i++)
printf("%d ",queue[i]);
}
}
void main()
{
int choice,val;

do
{

printf("\nMenu");
printf("\n1. Insert Element to Queue");
printf("\n2. Delete Element from Queue ");
printf("\n3. SHOW Queue Element");
printf("\n4.Exit");
printf("\nEnter your choice 1 to 4=");
scanf("%d",&choice);
switch (choice)
{
case 1:
printf("Enter value to be inserted=");
scanf("%d",&val);
Insert(val);
break;
case 2:
Delete();
break;

case 3:
Show();
break;
case 4:
exit(0);
break;

default:
printf("Invalid choice !");
break;
}

}while (choice<=3);

}