#include <assert.h>
#include <stdlib.h>
#include <string.h>
+#include <stdio.h>
void PrioQueueInit(PrioQueue *q, size_t memSize)
{
// do we need to insert before or after?
if(n->priority > current->priority) {
n->next = current;
- q->head = n->next;
+ q->head = n;
current->next = NULL;
return;
} else {
// ensuring we have prev populated
if(prev == NULL) {
prev = current;
+ current = current->next;
continue;
}
- if(prev->priority > n->priority > current->priority) {
+ if(prev->priority > n->priority && n->priority > current->priority) {
n->next = current;
prev->next = n;
return;
+ } else if(n->priority > prev->priority && prev->priority > current->priority) {
+ // must've been a head insert
+ n->next = prev;
+ q->head = n;
+ return;
}
prev = current;
current = current->next;
return size;
}
+
+void PrioQueuePrint(PrioQueue *q)
+{
+ PrioQueueNode *n = q->head;
+ int i = 0;
+
+ do {
+ printf("%d - data: %d, priority: %d\n", i, *( int*)n->data, n->priority);
+ ++i;
+ n = n->next;
+ } while(n != NULL);
+}
void PrioQueuePeek(PrioQueue *q, void *data);
void PrioQueueClear(PrioQueue *q);
size_t PrioQueueGetSize(PrioQueue *q);
+void PrioQueuePrint(PrioQueue *q);