ProAnswers.org

algorithm Remove an element from the queue

algorithm Remove an element from the queue

Removing an element from a queue

For array representation

void dequeue(queue *q){
if(q -> front != q -> rear)
q -> front = q -> front + 1;
}

For linked list representation

void dequeue(queue *q){
QNode *qnode;
if(q -> front == q -> rear) // Queue is empty
return;
qnode = q -> front;
q -> front = q -> front -> next;
free(qnode);
}