-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPQ.h
More file actions
64 lines (51 loc) · 1.59 KB
/
PQ.h
File metadata and controls
64 lines (51 loc) · 1.59 KB
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
https://powcoder.com
代写代考加微信 powcoder
Assignment Project Exam Help
Add WeChat powcoder
// Interface for a priority queue ADT
// This priority queue stores items of type int and uses priority values
// of type int, with smaller values having higher priority.
// COMP2521 Assignment 2
// Note: You MUST NOT modify this file.
#include <stdbool.h>
#ifndef PQ_H
#define PQ_H
typedef struct PQRep *PQ;
/**
* Creates a new priority queue
*/
PQ PQNew(void);
/**
* Adds an item with the given priority value to the priority queue. If
* the item already exists, its priority value is updated to the given
* priority value. The update is treated as if the item was removed and
* then reinserted.
*/
void PQInsert(PQ pq, int item, int priority);
/**
* Removes and returns the item with the smallest priority value from
* the priority queue. If multiple items have the same priority value,
* the item which was inserted the earliest out of those will be
* removed.
*/
int PQDequeue(PQ pq);
/**
* Updates the priority value of an item in the priority queue to the
* given priority value. If there is no such item in the priority queue,
* no action is taken. The update is treated as if the item was removed
* and then reinserted.
*/
void PQUpdate(PQ pq, int item, int priority);
/**
* Returns true if the given priority queue is empty, or false otherwise
*/
bool PQIsEmpty(PQ pq);
/**
* Prints the given priority queue to stdout for debugging purposes
*/
void PQShow(PQ pq);
/**
* Frees all memory associated with the given priority queue
*/
void PQFree(PQ pq);
#endif