Page 174 - DCAP201_FUNDAMENTALS_OF_DATA_STRUCTURES
P. 174
Unit 10: Queues
rear = 0; Notes
else
rear = rear + 1;
if( front == rear && queue[front] != NULL)
printf (“Queue Overflow”);
else
queue[rear] = y;
}
void deleteelement()
{
int deleted_front = 0;
if (front == NULL)
printf(“Error - Queue empty”);
else
{
deleted_front = queue[front];
queue[front] = NULL;
if (front == max-1)
front = 0;
else
front = front + 1;
}
}
Task Compare and contrast linear queue and circular queue.
10.3.2 Linked List Implementation of a Circular Queue
Linked list representation of a circular queue is more efficient as it uses space more efficiently,
of course with the extra cost of storing the pointers. Program given below gives the linked list
representation of a circular queue.
#include “stdio.h”
struct cq
{ int value;
int *next;
};
typedef struct cq *cqptr
cqptr p, *front, *rear;
main()
{
int choice,x;
/* Initialise the circular queue */
LOVELY PROFESSIONAL UNIVERSITY 167