-
Notifications
You must be signed in to change notification settings - Fork 1
/
node.h
54 lines (40 loc) · 836 Bytes
/
node.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
46
47
48
49
50
51
52
53
54
#ifndef NODE_H_
#define NODE_H_
#include <cstddef> /* NULL */
#include <limits>
#include <vector>
using std::vector;
typedef unsigned long int Size_t;
typedef unsigned char BYTE;
int const MAX_SYMBOLS =
1 + std::numeric_limits<BYTE>::max();
int const CHAR_BITS =
std::numeric_limits<BYTE>::digits;
class Node
{
public:
Size_t frequency;
BYTE c;
Node *left, *right;
Node(Size_t f, BYTE ch)
: frequency(f)
, c(ch)
, left(NULL)
, right(NULL)
{}
Node(Node *L = NULL, Node *R = NULL)
: frequency(L? L->frequency + R->frequency : 0)
, c('\0')
, left(L)
, right(R)
{}
};
struct ByFrequency
{
bool operator()(const Node *x, const Node *y) const
{
/* std::priority_queue is max heap */
return x->frequency > y->frequency;
}
};
#endif /* NODE_H_ */