pqueue.h
Type | |
This type defines the abstract type for a queue. | |
Functions | |
Allocates and returns an empty priority queue. | |
Frees the storage associated with the specified priority queue. | |
Adds a value to the queue in the order specified by priority . | |
Removes the data value at the head of the queue and returns it to the client. | |
Returns the data value at the head of the queue without removing it. | |
Returns the priority of the first entry in the queue, without removing it. | |
Tests whether the queue is empty. | |
Returns the number of values in the queue. | |
Removes all values from the queue. | |
Creates a copy of the priority queue. |
typedef struct PriorityQueueCDT *PriorityQueue;
PriorityQueue newPriorityQueue(void);
Usage:
pq = newPriorityQueue();
void freePriorityQueue(PriorityQueue pq);
Usage:
freePriorityQueue(pq);
void enqueue(PriorityQueue pq, void *value, double priority);
priority
.
In C, the priority
argument must have type double
,
which means that constants used to express priorities in the call to the
generic enqueue
function must include a decimal point.
Usage:
enqueue(pq, value, priority);
void *dequeue(PriorityQueue pq);
dequeue
calls
error
with an appropriate message.
Usage:
value = dequeue(pq);
void *peek(PriorityQueue pq);
peek
calls error
with
an appropriate message.
Usage:
value = peek(pq);
double peekPriority(PriorityQueue pq);
Usage:
priority = peekPriority(pq);
bool isEmpty(PriorityQueue pq);
Usage:
if (isEmpty(pq)) . . .
int size(PriorityQueue pq);
Usage:
n = size(pq);
void clear(PriorityQueue pq);
Usage:
clear(pq);
PriorityQueue clone(PriorityQueue pq);
clone
function
copies only the first level of the structure and does not copy the
individual elements.
Usage:
newpq = clone(pq);