//Huffman tree node abstract base class template class HuffNode { public: virtual ~HuffNode() {} virtual int weight() =0; virtual bool isLeaf() =0; }; template class LeafNode : public HuffNode { private: E it; int wgt; public: LeafNode(const E& val, int freq) { it = val; wgt = freq; } int weight() {return wgt;} E val() {return it;} bool isLeaf() {return true;} }; template class IntlNode : public HuffNode { private: HuffNode* lc; HuffNode* rc; int wgt; public: IntlNode(HuffNode* l, HuffNode* r) { wgt = l->weight() + r->weight(); lc = l; rc = r; } int weight() {return wgt;} bool isLeaf() {return false;} HuffNode* left() const {return lc;} void setLeft(HuffNode* b) { lc = (HuffNode*)b; } HuffNode* right() const {return rc;} void setRight(HuffNode* b) { rc = (HuffNode*)b; } };