나는 허프만 트리를 만들려고하는데, 나는 이미 C 언어로 정렬 된 주파수 배열을 가지고있다. c에서 huffman 트리를 만드는 방법 (이미 정렬 된 배열이 있음)
struct node
{
int value;
char letter; /* symbol */
struct node *left,*right; /* left and right subtrees */
};
typedef struct node Node;
및 주요 내부
() 내가 가진 :int main(){
Node *tree;
FILE *input, *output; //file input and output i am taking because i will take a input text file containing encoding of all 27 alphabets like a= 00001 b= 00010 etc.
buildHuffmanTree(&tree); // see it's function call there i already have done sorting of frequencies using qsort() BUT I DON'T KNOW WHAT TO DO AFTER.
return 0;
}
는 여기를 참조하십시오 여기 내 구조
입니다 내가 마음에 무엇을 가지고 정렬 된 배열과 지금void buildHuffmanTree(Node **tree){
Node *temp;
Node *array[27];
int i, subTrees = 27;
int smallOne;
for (i=0;i<27;i++)
{
array[i] = malloc(sizeof(Node));
array[i]->value = englishLetterFrequencies[i]; //this englishLetterFrequencies[27] contains the the frequencies of all 27 alphabtets like ={81,27,1,12.....up to 27 index of this array}
array[i]->letter = i;
array[i]->left = NULL;
array[i]->right = NULL;
}
//here is the sorting part:
int i = 0; int d,p;
printf("the array frequency is \n");
for(d=0;d < 27;d++)
printf("%d ",array[d]->value);
// sorting of arrays
qsort(array,27,sizeof(*array),cmpfunc);
//////////////////////////
printf("\n the sorted array frequency is \n");
for(p=0;p < 27;p++)
printf("%d ",array[p]->value); //So now this array[p]->value contains all the sorted frequency.
//I DON'T KNOW WHAT TO DO NOW
return;
}
. 우선 첫 번째 두 노드 (증가하는 정렬 된 배열 []의 첫 번째와 두 번째 인덱스에 있음)를 가져와 추가하고 다시 정렬하고이를 사용하여 트리를 만듭니다. 그러나 나는 그것을하기 위해 괭이를 모른다. 나는 초보자이다. 어느 누구도 그것을 구현하는 방법을 설명 할 수 있습니까?
소리 지르기. 그것은 당신에게 더 많은 답변을주지 않을 것입니다. – user2357112
이것은 (고함을 지르지 않고) 어쨌든 요청이었습니다. 답장을 보내 주셔서 감사합니다. – user3085082
그는 모든 모자를 사용하지 말아야합니다. 대신이 질문을 편집하십시오. –