Section 10.4
10 Data Structures
10.4 Queues
In a queue, new items are added at the end.
Items are retreived (or deleted) from the front of the queue.
This is a FIFO (First In - First Out) data structure.
The simplest way of implementing a queue in memory is to use an array with four
variables.
Example
At first the queue is empty.
Roy and James join the queue.
Now David, Debbie and Sam join the queue. Roy and James leave.
There is now no more space at the rear of the queue.
10.4.1 Circular Queues
The most common solution to the problem of queue overflow is to make the rear of
the queue 'wrap around' to the start.
Items leave from the front. If front > limit then front = 1.
Items are added to the rear. Add one to rear pointer. If rear > limit then
rear = 1.
Retrieving/Deleting An Item From A Circular Queue
First check that the queue is not empty. If it is not empty then the first item
is placed into a variable, the front pointer in incremented (cyclically) and the
size is decreased by one.