mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-03-20 11:58:14 +08:00
style: lint huffman.cpp (#2733)
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user