Name
pqueue_init
Synopsis
void pqueue_init(PQueue *pqueue
, int (*compare
)(const void *key1
, const void *key2
), void (*destroy
)(void *data
));
Return Value
None.
Description
Initializes the priority queue specified by
pqueue
. This operation must be called
for a priority queue before it can be used with any other
operation. The compare
argument is a
function used by various priority queue operations in maintaining
the priority queue’s heap property. This function should return 1
if key1
>
key2
, if
key1
= key2
,
and -1 if key1
<
key2
for a priority queue in which
large keys have a higher priority. For a priority queue in which
smaller keys have a higher priority,
compare
should reverse the cases that
return 1 and -1. The destroy
argument
provides a way to free dynamically allocated data when
pqueue_destroy is called. For example, if the
priority queue contains data dynamically allocated using
malloc, destroy
should be set to free to free the data as the
priority queue is destroyed. For structured data containing
several dynamically allocated members,
destroy
should be set to a user-defined
function that calls free for each dynamically
allocated member as well as for the structure itself. For a
priority queue containing data that should not be freed,
destroy
should be set to NULL.
Complexity
O (1)
Get Mastering Algorithms with C now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.