Page 170 - DCAP201_FUNDAMENTALS_OF_DATA_STRUCTURES
P. 170
Unit 10: Queues
case 1 : Notes
printf (“Enter element to be added :”);
scanf(“%d”,&x); Queues
add(&q,x);
break;
case 2 :
delete();
break;
}
}
add(y)
{
++q.rear;
if (q.rear < QUEUE_LENGTH)
q.element[q.rear] = y;
else
printf(“Queue overflow”)
}
delete()
{
if q.front > q.rear printf(“Queue empty”);
else{
x = q.element[q.front];
q.front++;
}
return x;
}
10.1.2 Linked List Implementation of a Queue
The basic element of a linked list is a “record” structure of at least two fields. The object that
holds the data and refers to the next element in the list is called a node.
Figure 10.4: Structure of a Node
Notes The data component may contain data of any type. Ptrnext is a reference to the next
element in the queue structure.
LOVELY PROFESSIONAL UNIVERSITY 163