STATUS: stable Priority queue. More...
#include "definitions.h"
#include <stdio.h>
Go to the source code of this file.
Data Structures | |
struct | PQnode |
a node in the PQueue. More... | |
struct | PriorityQueue |
the head of the PQueue. More... | |
Functions | |
void | pq_free (PriorityQueue *pq) |
PriorityQueue * | pq_init () |
void | pq_insert (PriorityQueue *pq, void *c, double prior) |
void * | pq_pop (PriorityQueue *pq) |
PQnode * | pq_pop_node (PriorityQueue *pq) |
void | pq_print (FILE *out, PriorityQueue *pq) |
STATUS: stable Priority queue.
Smaller priority values indicate higher priority.
The implementation is based on a single-linked list. Popping elements is therefore in O(1), inserting in O(N).
Usage is as follows:
PriorityQueue *pq=pq_init(); int stuff[] = {1, 2, 3, 4}; pq_insert( pq, (void*)&(stuff[0]), 10 ); ... pq_insert( pq, (void*)&(stuff[3]), 1 ); int priorel=*((int*)pq_pop( pq )); int nextprior=*((int*)pq_pop( pq )); ... pq_free( pq );
Definition in file pqueue.h.
void pq_free | ( | PriorityQueue * | pq | ) |
PriorityQueue* pq_init | ( | ) |
void pq_insert | ( | PriorityQueue * | pq, | |
void * | c, | |||
double | prior | |||
) |
void* pq_pop | ( | PriorityQueue * | pq | ) |
pop the data with highest priority in the PQ. if you need access to the priority as well, use pq_pop_node(). The corresponding node is removed from the PQ;
pq | the PQ |
PQnode* pq_pop_node | ( | PriorityQueue * | pq | ) |
void pq_print | ( | FILE * | out, | |
PriorityQueue * | pq | |||
) |