There are four types of Queue:
1. Simple Queue
2. Circular Queue
3. Priority Queue
4. Dequeue (Double Ended Queue)
1. Simple Queue
Simple queue defines the simple operation of queue in which insertion occurs at the rear of the list and deletion occurs at the front of the list.
Example: Program for Simple Queue
#include <stdio.h>
#define N 6
int queue[N]={0};
int rear=0,front=0;
void insert(void);
void delet(void);
void display(void);
void create(void);
void main()
{
int ch=0;
while(ch!=4)
{
printf("\n Size of the Queue is : %d",N);
printf("\n 1.Insert");
printf("\n 2.Delete");
printf("\n 3.Display");
printf("\n 4.Exit");
printf("\n 5.Create\n");
printf("\n Enter Your Choice : \n");
scanf("\n %d",&ch);
switch(ch)
{
case 1:
insert();
break;
case 2:
delet();
break;
case 3:
display();
break;
case 4:
create();
break;
case 5:
printf("\n\t Exit");
break;
}
}
}
void insert(void) //Insert Function
{
int t;
if(rear<N)
{
printf("\n\t Enter Element in a Queue : ");
scanf("%d",&t);
queue[rear]=t;
rear++;
}
else
{
printf("\n\t Queue is Overflow");
}
}
void delet(void) //Delete Function
{
int i;
printf("\n\t %d gets deleted.........",queue[front]);
queue[front]=0;
front++;
}
void display(void) //Display Function
{
int i;
for(i=front;i<rear;i++)
{
printf("\n\t %d",queue[i]);
}
}
void create(void) //Create Fucntion
{
int t;
printf("\n\t Enter Element in a Queue : ");
scanf("%d",&t);
front=0;
queue[front]=t;
rear=front+1;
}
Output:
1. Insert

2. Display

3. Delete



