style: lint huffman.cpp (#2733)

This commit is contained in:
Piotr Idzik
2024-09-15 10:54:44 +02:00
committed by GitHub
parent 8df7a884f5
commit a0b7dee79e

View File

@@ -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<MinHeapNode*, vector<MinHeapNode*>, 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;