- #1
anonim
- 40
- 2
- Homework Statement
- Taking a string, creating the Huffman coding tree and encrypting each character
- Relevant Equations
- -
First, I get the string and I find the frequency of the every character. My struct is:
I write this to create Huffman tree:
But I do not know how can I add the frequency the tree, how can I know the number should be right or left?
C:
typedef struct huffman_tree{
char c;
int freq; //unsigned?
struct huffman_tree *left; // 0 (left)
struct huffman_tree *right; // 1 (right)
}huffman_tree;
I write this to create Huffman tree:
Code:
huffman_tree *huffman_node_create(char data, unsigned int frequency)
{
huffman_tree *node = malloc(sizeof(huffman_tree));
node->data = data;
node->frequency = frequency;
node->left = NULL;
node->right = NULL;
return node;
}