Initial
This commit is contained in:
24
node.h
Normal file
24
node.h
Normal file
@ -0,0 +1,24 @@
|
||||
// A Tree node
|
||||
class Node {
|
||||
private:
|
||||
char ch;
|
||||
int freq;
|
||||
Node *left, *right;
|
||||
public:
|
||||
Node(char ch, int freq, Node* left, Node* right) : ch(ch), freq(freq), left(left), right(right) {};
|
||||
|
||||
const int getFreq() { return this->freq; };
|
||||
Node *getLeft() { return this->left; };
|
||||
Node *getRight() { return this->right; };
|
||||
const bool isLeaf() { return !this->right && !this->left; };
|
||||
const char getChar() { return this->ch; };
|
||||
};
|
||||
|
||||
struct NodeComp
|
||||
{
|
||||
bool operator()(Node *l, Node *r)
|
||||
{
|
||||
// highest priority item has lowest frequency
|
||||
return l->getFreq() > r->getFreq();
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user