-1
내가 만든 허프만 디코딩 기능에 약간의 문제가 있습니다. 누군가 내 프로그램이 무한 루프를 일으키는 이유를 알고 있는지 궁금합니다. 아래는 내 기능과 내가 어떻게 그것을 caled. 카운터가 8에 도달하면 읽을 비트가 더 이상 없기 때문에 함수에서 빠져 나가야합니다. 여기에 있습니다 :허프만 디코딩에서 재귀 함수가 빠져 나옴
HuffmanNode *rodee = createTree(freqArray2, 256); //holds the huffman tree
HuffmanNode *temporaryNode; //temporary node for traversing
temporaryNode = rodee; //first the temporary node is equal to the root
while(cin.read((char*)&w, sizeof(w))
{
traverseCode(temporaryNode, rodee, bits, count);
count = 0; //reset the count back to 0 for the next time the function is called
} //as I read in a byte of 8 bits (I converted the bytes to bits in another function not shown
void traverseCode(HuffmanNode *temp, HuffmanNode *root, unsigned char *bits, int counter)
{
if(counter >= 7)
{
counter = 0;
return;
}
if(temp->getLeft() == NULL && temp->getRight() == NULL)
{
cout << temp->getLetter();
temp = root;
traverseCode(temp, root, bits, counter);
}
if((int)bits[counter] == 0)
{
traverseCode(temp->getLeft(), root, bits, counter++);
}
if((int)bits[counter] == 1)
{
traverseCode(temp->getRight(), root, bits, counter++);
}
}
내 기능이 무한 루프로가는 이유는 누구이며 어떻게 해결할 수 있을까요? 감사!