We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5227e00 commit 4bf9a8aCopy full SHA for 4bf9a8a
contents/huffman_encoding/code/c/huffman.c
@@ -134,6 +134,15 @@ struct tree* generate_tree(const char* str) {
134
}
135
136
137
+ if (heap.length == 1) {
138
+ struct tree* leaf = heap_pop(&heap);
139
+ struct tree* root = calloc(0, sizeof(struct tree));
140
+ root->left = leaf;
141
+ root->count = leaf->count;
142
+ heap_free(&heap);
143
+ return root;
144
+ }
145
+
146
while (heap.length > 1) {
147
struct tree* left = heap_pop(&heap);
148
struct tree* right = heap_pop(&heap);
0 commit comments