Обновить sk1/compressor.c
This commit is contained in:
parent
ce5c50d78c
commit
0c18bdde02
@ -149,7 +149,12 @@ void generateCodes(HuffmanNode* root, char* arr, int top, char** codes) {
|
|||||||
codes[root->data] = strdup(arr);
|
codes[root->data] = strdup(arr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void free_huffman_tree(Node* root) {
|
||||||
|
if (!root) return;
|
||||||
|
free_huffman_tree(root->left);
|
||||||
|
free_huffman_tree(root->right);
|
||||||
|
free(root);
|
||||||
|
}
|
||||||
// Function to compress a file
|
// Function to compress a file
|
||||||
int compress_1(const char* input_file, const char* output_file) {
|
int compress_1(const char* input_file, const char* output_file) {
|
||||||
FILE* input = fopen(input_file, "rb");
|
FILE* input = fopen(input_file, "rb");
|
||||||
@ -216,6 +221,7 @@ int compress_1(const char* input_file, const char* output_file) {
|
|||||||
|
|
||||||
fclose(input);
|
fclose(input);
|
||||||
fclose(output);
|
fclose(output);
|
||||||
|
free_huffman_tree(root);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,6 +288,6 @@ int decompress_1(const char* input_file_name, const char* output_file_name) {
|
|||||||
|
|
||||||
fclose(input);
|
fclose(input);
|
||||||
fclose(output);
|
fclose(output);
|
||||||
|
free_huffman_tree(root);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user