-
Notifications
You must be signed in to change notification settings - Fork 0
/
pq.c
133 lines (114 loc) · 3.59 KB
/
pq.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
* In this file, you will write the structures and functions needed to
* implement a priority queue. Feel free to implement any helper functions
* you need in this file to implement a priority queue. Make sure to add your
* name and @oregonstate.edu email address below:
*
* Name:
* Email:
*/
#include <stdlib.h>
#include "pq.h"
/*
* This is the structure that represents a priority queue. You must define
* this struct to contain the data needed to implement a priority queue.
* in addition, you want to define an element struct with both data and priority,
* corresponding to the elements of the priority queue.
*/
struct pq;
/*
* This function should allocate and initialize an empty priority queue and
* return a pointer to it.
*/
struct pq* pq_create() {
return NULL;
}
/*
* This function should free the memory allocated to a given priority queue.
* Note that this function SHOULD NOT free the individual elements stored in
* the priority queue. That is the responsibility of the caller.
*
* Params:
* pq - the priority queue to be destroyed. May not be NULL.
*/
void pq_free(struct pq* pq) {
}
/*
* This function should return 1 if the specified priority queue is empty and
* 0 otherwise.
*
* Params:
* pq - the priority queue whose emptiness is to be checked. May not be
* NULL.
*
* Return:
* Should return 1 if pq is empty and 0 otherwise.
*/
int pq_isempty(struct pq* pq) {
return 1;
}
/*
* This function should insert a given element into a priority queue with a
* specified priority value. Note that in this implementation, higher priority
* values are given precedent, and higher place in the queue. In other words, the
* element in the priority queue with the highest priority value should be the
* FIRST one returned.
*
* Params:
* pq - the priority queue into which to insert an element. May not be
* NULL.
* data - the data value to be inserted into pq.
* priority - the priority value to be assigned to the newly-inserted
* element. Note that in this implementation, higher priority values
* should correspond to the first elements. In other words,
* the element in the priority queue with the highest priority value should
* be the FIRST one returned.
*/
void pq_insert(struct pq* pq, void* data, int priority) {
}
/*
* This function should return the data of the first element in a priority
* queue, i.e. the data associated with the element with highest priority value.
*
* Params:
* pq - the priority queue from which to fetch a value. May not be NULL or
* empty.
*
* Return:
* Should return the data of the first item in pq, i.e. the item with
* max priority value.
*/
void* pq_max(struct pq* pq) {
return NULL;
}
/*
* This function should return the priority value of the first item in a
* priority queue, i.e. the item with highest priority value.
*
* Params:
* pq - the priority queue from which to fetch a priority value. May not be
* NULL or empty.
*
* Return:
* Should return the priority value of the first item in pq, i.e. the item
* with highest priority value.
*/
int pq_max_priority(struct pq* pq) {
return 0;
}
/*
* This function should return the value of the first item in a priority
* queue, i.e. the item with highest priority value, and then remove that item
* from the queue.
*
* Params:
* pq - the priority queue from which to remove a value. May not be NULL or
* empty.
*
* Return:
* Should return the value of the first item in pq, i.e. the item with
* highest priority value.
*/
void* pq_max_dequeue(struct pq* pq) {
return NULL;
}