Обновить sk1/compressor.c
This commit is contained in:
		
							parent
							
								
									c4f58c0edd
								
							
						
					
					
						commit
						6c5368fde3
					
				| @ -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
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user