Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions greedy_algorithms/huffman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ struct MinHeapNode {
}
};

void deleteAll(const MinHeapNode* const root) {
if (root) {
deleteAll(root->left);
deleteAll(root->right);
delete root;
}
}

// For comparison of
// two heap nodes (needed in min heap)
struct compare {
Expand Down Expand Up @@ -85,6 +93,7 @@ void HuffmanCodes(char data[], int freq[], int size) {
// Print Huffman codes using
// the Huffman tree built above
printCodes(minHeap.top(), "");
deleteAll(minHeap.top());
}

// Driver program to test above functions
Expand Down
Loading