-
Notifications
You must be signed in to change notification settings - Fork 0
/
prio.c
68 lines (53 loc) · 1.24 KB
/
prio.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <stdlib.h>
#include "prio.h"
/*
A binary min heap implemented as a heapyfied array
*/
/* define an priorityQueueEntry */
/*struct priorityQueueEntry{
struct priorityQueueEntry parent;
struct priorityQueueEntry child;
void* data;
int key;
};
typedef struct priorityQueueEntry priorityQueueEntry;
*/
/* define a priorityQueue as the initial entry */
/*struct priorityQueue{
priorityQueueEntry root;
};
typedef struct priorityQueue priorityQueue;
*/
priorityQueue* newPriorityQueue(){
priorityQueue *queue = malloc(sizeof(priorityQueue));
return queue;
}
priorityQueueEntry priorityQueueEntryInsert(\
priorityQueue* queue,\
int key,\
void* data\
){
/* find the first node in queue */
priorityQueueEntry* target = &queue->root;
/* create entry */
priorityQueueEntry* entry = malloc(sizeof(priorityQueueEntry));
/* populate entry */
entry->child = NULL;
entry->key = key;
entry->data = data;
/* as long as a child node is definded be that child node */
while(target->child){
target=target->child;
}
target->child = entry;
queue->size++;
/* remove entropy from heap */
heapify(queue);
return(*entry);
}
heapify(\
priorityQueueEntry* root\
){
int smallest = root.key;
if(smallest < (*root.childl).key)
}