Skip to content

Commit

Permalink
style: lint huffman.cpp (#2733)
Browse files Browse the repository at this point in the history
  • Loading branch information
vil02 authored Sep 15, 2024
1 parent 8df7a88 commit a0b7dee
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions greedy_algorithms/huffman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit a0b7dee

Please sign in to comment.