#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
typedef strUCt
{
unsigned int Weight;
unsigned int Parent;
unsigned int lChild;
unsigned int rChild;
}HTNode,*HuffmanTree;
typedef char **HuffmanCode;
int LookFor(char *str,char letter,int count);
void OutputWeight(char *Data,int Length,
char **WhatLetter,
int **Weight,int *Count);
void HuffmanCoding(HuffmanTree *HT,
HuffmanCode *HC,
int *Weight,
int Count);
void Select(HuffmanTree HT,int Count,int *s1,int *s2);
int main()
{
HuffmanTree HT;
HuffmanCode HC;
char Data[100];
char *WhatLetter;
int *Weight;
int Count;
int i;
printf("Please input the line:");
/* Example: aaaaaaaaaaaaaabcccccc*/
scanf("%s",Data);
printf("\n");
OutputWeight(Data,strlen(Data),
&WhatLetter,
&Weight,
&Count);
HuffmanCoding(&HT,&HC,Weight,Count);
printf(" Letter Weight Code\n");
for(i=0;i<Count;i++)
{
printf(" %c ",WhatLetter[i]);
printf("%d ",Weight[i]);
printf("%s\n",HC[i+1]);
}
printf("\n");
getch();
return 0;
}
void HuffmanCoding(HuffmanTree *HT,
HuffmanCode *HC,
int *Weight,
int Count)
{
int i;
int s1,s2;
int TotalLength;
HuffmanTree p;
char* cd;