Dequeue
A Dequeue can be represented as follows
Let the total size of elements be n in this Dequeue represented as an array int array[n];
Then
front = index of the first element
Rear = index of the last element
If front = rear then we suppose that the Dequeue is empty
The Dequeue grows from front side till the index of the front becomes 0 and from rear side till the index of the rear equals the array size (n-1).
Now the functions for inserting at the front end of the Dequeue is:-
Insert_front ( int data )
{
if ( front == 0 )
printf (“Dequeue is full from the front end”);
else
{
front--;
array[front] = data;
}
}
Inserting from the rear end is:-
insert_rear ( int data )
{
if (rear == n-1)
printf(“Dequeue is full from rear end”);
else
{
rear++;
array [ rear ] = data;
}
}
Deleting from the front end: -
int delete_front ()
{
if (front == rear)
printf ( “the Dequeue is empty”);
else
return ( array [ front++ ] );
}
Deleting from the rear end:-
int delete_rear ()
{
if ( front == rear )
printf(“ the Dequeue is empty ”);
else
return ( array [ rear-- ] );
}