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

Queue->Circular queue->Delete operation

As I said earlier, every time we delete an element from the queue, the "front" value increments by 1 till the time it reaches the upper limit of queue; after which it starts all over again from 0. Here, we'll be checking the "Queue empty" condition; and if the queue is empty then we'll flash an error message or else we'll delete that front element.

The queue is supposed to be Empty when it contains a NULL value for its "front" element. Fine!

Algorithm for deletion:-
Step-1: If the queue is empty then say "empty queue" and quit; else continue
Step-2: Delete the "front" element
Step-3: If the "front" is pointing to the last position of the queue then step-4 else step-5
Step-4: Make the "front" point to the first position in the queue and quit
Step-5: Increment the "front" position by one 

C implementation:-
int max;          /*the maximum limit has already been set*/
static int queue[max];
int front=0, rear=-1;  /*queue is initially empty*/
..
..
main( )
{
..
..
addval(23);
..
del_value = delval( );
..
addval(47);
..
}

int delval( )
{
int deleted_front = 0;
 if (front == NULL)     /*step-1*/
      printf("Queue empty");
   else
     {
       deleted_front = queue[front];
       queue[front] = NULL;       /*step-2*/
       if (front == max-1)    /*step-3*/
          front = 0;          /*step-4*/
       else
          front = front + 1;/*step-5*/
     }
return(deleted_front);
}

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