Обновить sk1/compressor.c

This commit is contained in:
Yevhen Kozirovskyi 2025-01-19 18:06:11 +00:00
parent c4f58c0edd
commit 6c5368fde3

View File

@ -136,23 +136,7 @@ struct MinHeapNode* buildHuffmanTree(unsigned char data[], int freq[], int size)
} }
// Print Huffman Codes to a map // Print Huffman Codes to a map
void storeCodes(struct MinHeapNode* root, char** codes, char* currentCode, int top) {
if (!root) return;
if (root->left) {
currentCode[top] = '0';
storeCodes(root->left, codes, currentCode, top + 1);
}
if (root->right) {
currentCode[top] = '1';
storeCodes(root->right, codes, currentCode, top + 1);
}
if (!(root->left) && !(root->right)) {
currentCode[top] = '\0';
codes[root->data] = (char*)malloc(strlen(currentCode) + 1); // Use malloc instead of strdup
strcpy(codes[root->data], currentCode); // Copy the string
}
}
// Updated compressFile function // Updated compressFile function