Free Web Hosting Provider - Web Hosting - E-commerce - High Speed Internet - Free Web Page
Search the Web

Queue->Array implementation->Delete operation

When an element leaves the queue the 'front' gets incremented by one. Every time before deletion we'll check for the 'queue empty' condition. If the queue is not empty, put a NULL value at the position pointed by 'front' and increment the value of 'front' by 1.

Algorithm:-
Step-1: If the queue is empty then quit else go to step-2
Step-2: Put a NULL value at the position pointed by 'front'. Increment the 'front' by 1.

C implementation:-
static int queue[max];
int front = 0, rear = -1; /*when the queue is empty*/
..
..
int delete( )
{
 int del_val =0;   /*holds the deleted value*/
 if(front > rear) printf("Queue empty");
   else
     {
      del_val = queue[front];
      queue[front] = NULL;  /*this represents that the element has been deleted*/
      front = front + 1;
     }
return(del_val);
}

Related Operations:
Queues - Concepts
Array implementation - add( ) and delete( )
Linked List implementation - add( ) and delete( )
Circular queues - add( ) and delete( )

Index || Doubts / Clarifications || Related Topics || Web Links