www.pudn.com > huffman.rar > makeList.c


//make the Haffman code list. 
#include "MyAssert.h" 
#include "Ulti.h" 
#include "ECBTree.h" 
#include  
#include  
#include  
 
#define LENGTH 128 
#define DEBUG 0 
#define TEST   1 
 
int getBinLen(unsigned long inData) 
{ 
	int i=0; 
	if( inData==0)  
		return 1; 
	else		 
	 
	while(inData!=0) 
	{ 
		inData/=2; 
		i++; 
	} 
	return i; 
} 
 
 
void main(int argc,char* argv[]) 
{ 
	//core data. 
	long wList[LENGTH]={0,0,0,0,0,0,0,0,0,50,887,0,0,887,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5044,53,62,14,1,6,19,50,63,72,9,11,217,622,275,59,95,53,73,23,8,28,13,8,15,7,53,41,10,29,25,39,1,167,85,131,102,107,86,73,62,117,49,48,82,137,97,73,129,5,93,229,165,50,52,70,16,40,17,9,7,9,0,2,0,1759,308,671,782,2635,417,440,858,1631,27,216,932,564,1466,1658,429,45,1354,1341,1712,649,251,326,45,408,47,6,27,6,1,0}; 
	PHtTree myHtTree; 
 
	//file data. 
	char outputFileName[]="haffList.txt"; 
	FILE* outputFile; 
 
	HaffCode haffList[LENGTH]; 
			 
	int i; 
		 
	assertF((outputFile=fopen(outputFileName,"wb"))!=NULL,"output file error"); 
	 
	if (DEBUG) 
		printf("output file open success\n"); 
		 
	//step1: constructing the haffman trees. 
	myHtTree=haffmanAlgorithm(LENGTH,wList); 
	 
	if(DEBUG) 
		preHtOrder(myHtTree,myHtTree->rootIndex); 
	 
	//step2: 
	for(i=0;irootIndex,0x000000,0,haffList); 
	 
		fprintf(outputFile,"haffCode List:\r\n"); 
		for(i=0;i