#include <priorityqueue.h>
Public Member Functions | |
| PriorityQueue () | |
| PriorityQueue (SEARCH_TYPE) | |
| bool | Add (GENERIC_NODE elem, Priority priority) |
| bool | PopLowest (GENERIC_NODE &elem) |
| Priority & | TopKey (void) |
| Returns the the smallest priority of all vertices in priority queue. | |
| bool | empty (void) |
| Return whether queue is empty. | |
| int | size (void) |
| void | Clear (void) |
| void | Update (GENERIC_NODE elem, Priority p) |
| void Update(GENERIC_NODE elem, Priority p, bool (*cmp)(GENERIC_NODE,GENERIC_NODE)); | |
| GENERIC_NODE | Element (unsigned int i) |
| bool | Remove (GENERIC_NODE elem) |
| bool Remove(GENERIC_NODE elem, bool (*cmp)(GENERIC_NODE,GENERIC_NODE)); | |
| bool | Search (GENERIC_NODE src, Priority &p) |
| void | Dump () |
| bool Search(GENERIC_NODE src, Priority& p, bool (*cmp)(GENERIC_NODE,GENERIC_NODE)); | |
| bool | HeapDecreasePriority (unsigned int i) |
| bool | HeapIncreasePriority (unsigned int i) |
| void | Copy (PriorityQueue &p) |
Static Public Attributes | |
| Priority | MINPRIORITY |
Private Member Functions | |
| bool | Exchange (unsigned int a, unsigned int b) |
| unsigned int | Left (unsigned int i) |
| unsigned int | Right (unsigned int i) |
| unsigned int | Parent (unsigned int i) |
| void | MinHeapify (unsigned int i) |
Private Attributes | |
| unsigned int | m_ElemCount |
| Priority | m_Priority [MAXDEPTH] |
| GENERIC_NODE | Gm_Elems [MAXDEPTH] |
PriorityQueue Class. This is a heap-based minimum priority queue. The number of elements the queue can store is kept in the MAXDEPTH constant in the header file. The details of how the queue works can be found in Introduction to Algorithms, by CLRS.
|
|
|
|
|
|
|
||||||||||||
|
Adds a new element to the priority queue and resorts the queue. Will return failure if the queue is full.
|
|
|
|
|
|
|
|
|
bool Search(GENERIC_NODE src, Priority& p, bool (*cmp)(GENERIC_NODE,GENERIC_NODE)); Dumps the queue data to STDOUT. |
|
|
|
|
|
Return whether queue is empty.
|
|
||||||||||||
|
Exchanges the two elements at the given locations. Does NOT resort the queue.
|
|
|
Resorts the queue at the element argument, assumes that the priority of the element has its priority reduced. NOTE: Requires the priority to be reduced prior to the call.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Pops the element with the lowest priority from the queue. The element is removed and the queue is resorted. Will return failure if the queue is empty.
|
|
|
bool Remove(GENERIC_NODE elem, bool (*cmp)(GENERIC_NODE,GENERIC_NODE)); Removes an element from the queue using the passed comparison function and resorts the queue. Will return failure if no matching element is found.
|
|
|
|
|
||||||||||||
|
Searches for an element in the queue and returns whether the element is found. The queue is unmodified.
|
|
|
|
|
|
Returns the the smallest priority of all vertices in priority queue.
|
|
||||||||||||
|
void Update(GENERIC_NODE elem, Priority p, bool (*cmp)(GENERIC_NODE,GENERIC_NODE));
|
|
|
The array of elements. Shares the same indices of the priority array. It has a flattened tree structure. |
|
|
The number of elements in the queue. Initially initialized to 0. |
|
|
The array of element priorities. Shares the same indices of the element array. It has a flattened tree structure. |
|
|
Constructor. Initializes the class instance. |
1.3