@@ -34,16 +34,15 @@ void deleteAll(const MinHeapNode* const root) {
3434// For comparison of
3535// two heap nodes (needed in min heap)
3636struct compare {
37- bool operator ()(MinHeapNode* l, MinHeapNode* r)
38-
39- {
40- return (l->freq > r->freq );
37+ bool operator ()(const MinHeapNode* const l,
38+ const MinHeapNode* const r) const {
39+ return l->freq > r->freq ;
4140 }
4241};
4342
4443// Prints huffman codes from
4544// the root of Huffman Tree.
46- void printCodes (struct MinHeapNode * root, string str) {
45+ void printCodes (struct MinHeapNode * root, const string& str) {
4746 if (!root)
4847 return ;
4948
@@ -56,8 +55,8 @@ void printCodes(struct MinHeapNode* root, string str) {
5655
5756// The main function that builds a Huffman Tree and
5857// print codes by traversing the built Huffman Tree
59- void HuffmanCodes (char data[], int freq[], int size) {
60- struct MinHeapNode *left, *right, *top ;
58+ void HuffmanCodes (const char data[], const int freq[], int size) {
59+ struct MinHeapNode *left, *right;
6160
6261 // Create a min heap & inserts all characters of data[]
6362 priority_queue<MinHeapNode*, vector<MinHeapNode*>, compare> minHeap;
@@ -82,7 +81,7 @@ void HuffmanCodes(char data[], int freq[], int size) {
8281 // of this new node. Add this node
8382 // to the min heap '$' is a special value
8483 // for internal nodes, not used
85- top = new MinHeapNode (' $' , left->freq + right->freq );
84+ auto * const top = new MinHeapNode (' $' , left->freq + right->freq );
8685
8786 top->left = left;
8887 top->right = right;
0 commit comments