-
Notifications
You must be signed in to change notification settings - Fork 0
/
priqueue.h
executable file
·45 lines (32 loc) · 892 Bytes
/
priqueue.h
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
#include <string>
#define MAX 500
template <typename T>
class priqueue {
public:
typedef T element_type;
// function pointer typedef
// priorityfn: element_type -> int
typedef int (*priorityfn)(const element_type & item);
// constructor: takes a priority function for ordering
// items added
priqueue(priorityfn pri);
// add item to the list in order of priority
void add(const element_type & item);
// return first item in the list
element_type front() const;
// remove the first item in the list
void remove_front();
// the usual empty predicate
bool empty() const;
// Dom's excellect suggestion
size_t size() const;
private:
// private functions to reheap up and down
void _reheap_up(size_t i);
void _reheap_down(size_t i);
// member data:
size_t _size;
element_type _data[MAX];
priorityfn _pri;
};
#include "priqueue.cc"