Relative Content

Tag Archive for ctreehuffman-codeqsorthuffman-tree

Can’t build huffman tree in C, qsort fails

I try to implement huffman code in C. I have two arrays, one storing all the nodes and one that contains pointers to certain nodes. The second one contains the unfinished trees that I want to combine. I have to sort the trees to combine the two with the lowest frequency, but qsort() fails with a segfault. In there I try to compare the frequency member of my tree struct but that fails. When I try to access the frequency member outside of my compare function it works. (relevant part is the compareFrequeny function and the last while loop in huffman.c)