Business, Digital Marketing, SEO, Technology, Programming Languages, Computer

# Queue in Data Structure

## What is Queue-?

Queue is a collection of data item in which insertion and deletion takes place on opposite end. The insertion end is called rear and deletion end is called front. In queue we can perform two operations, i.e.., REAR and FRONT.
Queue always perform FIFO operation, i.e.., first in first out. A queue can be represented by the help of array and linked list.

#### Algorithm of Insertion of Queue in Data Structure

Step 1:- Begin
Step 2:- If Rear=(N-1) then
Step 3:- Input new item
Step 4:- Rear ⬅ Rear=1
Step 5:- Queue [Rear] ⬅ item
Step 6:- Exit

#### Algorithm of Deletion of Queue in Data Structure

Step 1:- Begin
Step 2:- If f=-1 then
print underflow and exit
Step 3:- Set item  ⬅ queue [front]
Step 4:- Front ⬅ front+2
Step 5:- Print deleted item
Step 6:- Exit

#### Program of Queue in Data Structure

#include<stdio.h>
#include<conio.h>
int queue[5],f=-1,r=-1;
void rear( );
void front( );
void show( );
void main( );
{
int ch;
clrscr( );
printf("1. REAR\n");
printf("2. FRONT\n");
printf("3. SHOW\n");
printf("4. EXIT");
while(1)
{
print("\nEnter choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1:rear( );
break;
case 2:front( );
break;
case 3:show( );
break;
case 4:exit( );
break;
default:printf("invalid option")
}
}
}
void rear( )
{
int item;
if(r==5-1)
{
printf("Queue is full");
}
else
{
if(f==-1)
{
f=o;
}
printf("insert element in queue: ");
scanf("%d",&item);
r=r+1;
queue[r]=item;
}
}
void front( )
{
if(f==-1)
{
printf("Queue is empty");
}
else
{
printf("DELETD %d",queue[f]);
f=f+1
}
}
void show( )
{
int i;
if(f==-1)
{
printf("Queue is empty");
for(i=f; i<=r, i==)
{
printf("%d",queue[i]);
}
}
}

### What is linked list in data structure-?

Linked list is the linear dat structure where data are not stored sequentially inside the computer memory, but they are linked with each other by the help of address.

### What is Sorting in data Structure-?

Sorting is a method to arrange N elements array in a particular format either ascending order or descending order.

### Types of Sorting in Data Structure

#### Basic Types:-

1. Bubble sort
2. Selection Sort
3. Insertion sort

4. Quick sort
5. Merge sort
6. Heap sort
7. Redix sort
8. Shell sort
9. Tree sort
10. Bucket sort

### What is Circular Linked List in Data Structure-?

The Circular Linked List is the variation of linked list where the first node point to last node point, and last node point to first node.