Files
mashzip/node.h
Andrey Gumirov 606ce553ac Initial
2024-01-08 02:39:45 +07:00

25 lines
628 B
C++

// 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();
}
};