Skip to content

Commit 4bf9a8a

Browse files
Gathrosleios
authored andcommitted
Fixed huffman edge case failure in C. (#661)
1 parent 5227e00 commit 4bf9a8a

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

‎contents/huffman_encoding/code/c/huffman.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,15 @@ struct tree* generate_tree(const char* str){
134134
}
135135
}
136136

137+
if (heap.length==1){
138+
structtree*leaf=heap_pop(&heap);
139+
structtree*root=calloc(0, sizeof(structtree));
140+
root->left=leaf;
141+
root->count=leaf->count;
142+
heap_free(&heap);
143+
returnroot;
144+
}
145+
137146
while (heap.length>1){
138147
structtree*left=heap_pop(&heap);
139148
structtree*right=heap_pop(&heap);

0 commit comments

Comments
(0)