MinHeapNode *left, *right;
17MinHeapNode(
chardata,
unsignedfreq)
28deleteAll(root->left);
29deleteAll(root->right);
39 returnl->freq > r->freq;
45voidprintCodes(
struct MinHeapNode* root,
const string& str) {
49 if(root->data !=
'$')
50cout << root->data <<
": "<< str <<
"\n";
52printCodes(root->left, str +
"0");
53printCodes(root->right, str +
"1");
58voidHuffmanCodes(
const char data[],
const intfreq[],
intsize) {
62priority_queue<MinHeapNode*, vector<MinHeapNode*>,
compare> minHeap;
64 for(
inti = 0; i < size; ++i)
68 while(minHeap.size() != 1) {
74right = minHeap.top();
84 auto*
consttop =
new MinHeapNode(
'$', left->freq + right->freq);
94printCodes(minHeap.top(),
"");
95deleteAll(minHeap.top());
100 chararr[] = {
'a',
'b',
'c',
'd',
'e',
'f'};
101 intfreq[] = {5, 9, 12, 13, 16, 45};
103 intsize =
sizeof(arr) /
sizeof(arr[0]);
105HuffmanCodes(arr, freq, size);
int main()
Main function.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4