queue.h

This interface defines a queue abstraction with first-in/first-out semantics.
Type
Queue This type defines the abstract type for a queue.
Functions
newQueue() Allocates and returns an empty queue.
freeQueue(queue) Frees the storage associated with the specified queue.
enqueue(queue, element) Adds an element to the end of the queue.
dequeue(queue) Removes the data value at the head of the queue and returns it to the client.
peek(queue) Returns the data value at the head of the queue without removing it.
isEmpty(queue) Tests whether the queue is empty.
size(queue) Returns the number of elements in the queue.
clear(queue) Removes all elements from the queue.
clone(queue) Creates a copy of the queue.

Type detail


typedef struct QueueCDT *Queue;
This type defines the abstract type for a queue.

Function detail


Queue newQueue(void);
Allocates and returns an empty queue.

Usage:

queue = newQueue();

void freeQueue(Queue queue);
Frees the storage associated with the specified queue.

Usage:

freeQueue(queue);

void enqueue(Queue queue, void *element);
Adds an element to the end of the queue.

Usage:

enqueue(queue, element);

void *dequeue(Queue queue);
Removes the data value at the head of the queue and returns it to the client. If the queue is empty, dequeue calls error with an appropriate message.

Usage:

element = dequeue(queue);

void *peek(Queue queue);
Returns the data value at the head of the queue without removing it. If the queue is empty, peek calls error with an appropriate message.

Usage:

element = peek(queue);

bool isEmpty(Queue queue);
Tests whether the queue is empty.

Usage:

if (isEmpty(queue)) . . .

int size(Queue queue);
Returns the number of elements in the queue.

Usage:

n = size(queue);

void clear(Queue queue);
Removes all elements from the queue.

Usage:

clear(queue);

Queue clone(Queue queue);
Creates a copy of the queue. The clone function copies only the first level of the structure and does not copy the individual elements.

Usage:

newqueue = clone(queue);