@@ -34,16 +34,15 @@ void deleteAll(const MinHeapNode* const root) {
34
34
// For comparison of
35
35
// two heap nodes (needed in min heap)
36
36
struct 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 ;
41
40
}
42
41
};
43
42
44
43
// Prints huffman codes from
45
44
// the root of Huffman Tree.
46
- void printCodes (struct MinHeapNode * root, string str) {
45
+ void printCodes (struct MinHeapNode * root, const string& str) {
47
46
if (!root)
48
47
return ;
49
48
@@ -56,8 +55,8 @@ void printCodes(struct MinHeapNode* root, string str) {
56
55
57
56
// The main function that builds a Huffman Tree and
58
57
// 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;
61
60
62
61
// Create a min heap & inserts all characters of data[]
63
62
priority_queue<MinHeapNode*, vector<MinHeapNode*>, compare> minHeap;
@@ -82,7 +81,7 @@ void HuffmanCodes(char data[], int freq[], int size) {
82
81
// of this new node. Add this node
83
82
// to the min heap '$' is a special value
84
83
// for internal nodes, not used
85
- top = new MinHeapNode (' $' , left->freq + right->freq );
84
+ auto * const top = new MinHeapNode (' $' , left->freq + right->freq );
86
85
87
86
top->left = left;
88
87
top->right = right;
0 commit comments