This commit is contained in:
Andrey Gumirov
2024-01-08 02:39:45 +07:00
parent fdcba0b869
commit 606ce553ac
9 changed files with 1594 additions and 0 deletions

24
node.h Normal file
View 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();
}
};