From a0b7dee79ec0523534bee9b0131bb60b1e0d76fe Mon Sep 17 00:00:00 2001 From: Piotr Idzik <65706193+vil02@users.noreply.github.com> Date: Sun, 15 Sep 2024 10:54:44 +0200 Subject: [PATCH] style: lint `huffman.cpp` (#2733) --- greedy_algorithms/huffman.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/greedy_algorithms/huffman.cpp b/greedy_algorithms/huffman.cpp index a63007422dd..a520d683010 100644 --- a/greedy_algorithms/huffman.cpp +++ b/greedy_algorithms/huffman.cpp @@ -34,16 +34,15 @@ void deleteAll(const MinHeapNode* const root) { // For comparison of // two heap nodes (needed in min heap) struct compare { - bool operator()(MinHeapNode* l, MinHeapNode* r) - - { - return (l->freq > r->freq); + bool operator()(const MinHeapNode* const l, + const MinHeapNode* const r) const { + return l->freq > r->freq; } }; // Prints huffman codes from // the root of Huffman Tree. -void printCodes(struct MinHeapNode* root, string str) { +void printCodes(struct MinHeapNode* root, const string& str) { if (!root) return; @@ -56,8 +55,8 @@ void printCodes(struct MinHeapNode* root, string str) { // The main function that builds a Huffman Tree and // print codes by traversing the built Huffman Tree -void HuffmanCodes(char data[], int freq[], int size) { - struct MinHeapNode *left, *right, *top; +void HuffmanCodes(const char data[], const int freq[], int size) { + struct MinHeapNode *left, *right; // Create a min heap & inserts all characters of data[] priority_queue, compare> minHeap; @@ -82,7 +81,7 @@ void HuffmanCodes(char data[], int freq[], int size) { // of this new node. Add this node // to the min heap '$' is a special value // for internal nodes, not used - top = new MinHeapNode('$', left->freq + right->freq); + auto* const top = new MinHeapNode('$', left->freq + right->freq); top->left = left; top->right = right;