6
6
7
7
8
8
9
+
10
+ /** This function will allocate a new heap priority queue then it will return its pointer.
11
+ *
12
+ * @param freeFn the free function pointer, that will be called to free the queue items
13
+ * @param cmp the comparator function pointer, that will be called to compare the queue items
14
+ * @return it will return the new allocated queue pointer
15
+ */
16
+
9
17
HPriorityQueue * hPriorityQueueInitialization (void (* freeFn )(void * ), int (* cmp )(const void * , const void * )) {
10
18
11
19
HPriorityQueue * queue = (HPriorityQueue * ) malloc (sizeof (HPriorityQueue ));
@@ -18,6 +26,14 @@ HPriorityQueue *hPriorityQueueInitialization(void (*freeFn)(void *), int (*cmp)(
18
26
19
27
20
28
29
+
30
+
31
+ /** This function will insert the passed item in the queue.
32
+ *
33
+ * @param queue the queue pointer
34
+ * @param item the new item pointer
35
+ */
36
+
21
37
void hpQueueEnqueue (HPriorityQueue * queue , void * item ) {
22
38
23
39
if (queue == NULL ) {
@@ -31,6 +47,14 @@ void hpQueueEnqueue(HPriorityQueue *queue, void *item) {
31
47
}
32
48
33
49
50
+
51
+
52
+ /** This function will insert all the passed array items in the queue.
53
+ *
54
+ * @param queue the queue pointer
55
+ * @param items the new items array pointer
56
+ * @param length the length of the new items array
57
+ */
34
58
void hpQueueEnqueueAll (HPriorityQueue * queue , void * items , int length ) {
35
59
36
60
if (queue == NULL ) {
@@ -45,6 +69,14 @@ void hpQueueEnqueueAll(HPriorityQueue *queue, void *items, int length) {
45
69
46
70
47
71
72
+
73
+ /** This function will remove the first item from the queue,
74
+ * then it will return it.
75
+ *
76
+ * @param queue the queue pointer
77
+ * @return it will return the first item in the queue
78
+ */
79
+
48
80
void * hpQueueDequeue (HPriorityQueue * queue ) {
49
81
50
82
if (queue == NULL ) {
@@ -59,6 +91,13 @@ void *hpQueueDequeue(HPriorityQueue *queue) {
59
91
60
92
61
93
94
+
95
+ /** This function will return the first item in the queue without removing it from the queue.
96
+ *
97
+ * @param queue the queue pointer
98
+ * @return it will return the first item in the queue
99
+ */
100
+
62
101
void * hpQueuePeek (HPriorityQueue * queue ) {
63
102
64
103
if (queue == NULL ) {
@@ -73,16 +112,43 @@ void *hpQueuePeek(HPriorityQueue *queue) {
73
112
74
113
75
114
115
+
116
+ /** This function will return the number of items in the queue.
117
+ *
118
+ * @param queue the queue pointer
119
+ * @return it will return the number of items in the queue
120
+ */
121
+
76
122
int hpQueueGetLength (HPriorityQueue * queue ) {
77
123
return binaryHeapGetSize (queue -> heap );
78
124
}
79
125
80
126
127
+
128
+
129
+ /** This function will check if the queue is empty or not,
130
+ * and if it was the function will return one (1),
131
+ * other wise it will return zero (0).
132
+ *
133
+ * @param queue the queue pointer
134
+ * @return it will return 1 if the queue was empty, other wise it will return 0
135
+ */
136
+
81
137
int hpQueueIsEmpty (HPriorityQueue * queue ) {
82
138
return binaryHeapIsEmpty (queue -> heap );
83
139
}
84
140
85
141
142
+
143
+
144
+ /** This function will return a double void array that contains the queue items.
145
+ *
146
+ * Note: the array will be sorted.
147
+ *
148
+ * @param queue the queue pointer
149
+ * @return it will return a double void array pointer, that contains the queue items
150
+ */
151
+
86
152
void * * hpQueueToArray (HPriorityQueue * queue ) {
87
153
void * * arr = binaryHeapToArray (queue -> heap );
88
154
@@ -97,12 +163,29 @@ void **hpQueueToArray(HPriorityQueue *queue) {
97
163
98
164
}
99
165
166
+
167
+
168
+
169
+ /** This function will clear the queue and free all it's items,
170
+ * without freeing the queue itself.
171
+ *
172
+ * @param queue the queue pointer
173
+ */
174
+
100
175
void clearHPQueue (HPriorityQueue * queue ) {
101
176
102
177
clearBinaryHeap (queue -> heap );
103
178
104
179
}
105
180
181
+
182
+
183
+
184
+ /** This function will destroy and free the queue and it's items.
185
+ *
186
+ * @param queue the queue pointer
187
+ */
188
+
106
189
void destroyHPQueue (HPriorityQueue * queue ) {
107
190
108
191
destroyBinaryHeap (queue -> heap );
0 commit comments