int queue[MAX]Â Â Â Â Â Â Â Â Â Â Â Â Â Â (MAX is the size of the array / queue)
Declare and initialize front and rear to -1
int front = -1;
int rear = -1;Create functions
void insert()Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â (to insert elements into the queue)
int pop()Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ( to delete elements from the queue)
void display()Â Â Â Â Â Â Â Â Â Â Â Â (to display elements of the queue)
Insert elements into the queue
In the insert function first check if the queue is full because in case the queue is full then we will not be able to insert any elements into the queue.
void insert(int element) { if(rear==MAX-1) { printf("nQueue is Fulln"); return; } if(front==-1) { front = 0; } rear=rear+1; queue[rear]=element; }
If the queue is full then queue is full will be printed and with the help of that return statement we will come of of the insert function or in other words the insert function will terminate.
If the queue is not full then the following statements will be executed.
if(front==-1)
 {
 front = 0;Â
}Â
rear=rear+1;Â
queue[rear]=element;
Â
First time when an element is inserted into the queue then the value of front from -1 will become equal to zero with the help of this if statement in
the insert function.
Â
if(front==-1)Â
{Â
front = 0;
 }rear=rear+1; Value of rear will be incremented by 1 and a new element will be inserted
into the queue with the help of this statement
queue[rear]=element;Â
int del() { int element; if(front==-1 || front==rear+1) { printf("Queue is Emptyn"); return; } element = queue[front]; front = front + 1; printf("%d has been deletedn", element); return element; }
If the queue is full then queue is full will be printed and that return statement will terminate the del function.
If the queue is not full the the following statements will be executed.
element = queue[front];
front = front + 1;
printf(“%d has been deletedn”, element);
return element;
Variable element will store the value that will be deleted from the queue.
An Element in the queue is deleted by incrementing the value of front by 1 which is done using this statement.
front = front + 1;
printf(“%d has been deletedn”, element);Â Â Â This print statement prints the value that has been deleted from the queue.