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