⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 makelist.c

📁 用哈夫曼编码实现文件压缩和解压缩. 压缩过程的实现:1创建Haffman树&#61664 2打开需压缩文件&#61664 3将需压缩文件中的每个ascii码对应的haffman编码按bit单位输出&
💻 C
字号:
//make the Haffman code list.
#include "MyAssert.h"
#include "Ulti.h"
#include "ECBTree.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#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;i<LENGTH;i++)
		haffList[i].asciiCode=(char)i;
	
	if(TEST)
	{
		preHaffListMake(myHtTree,myHtTree->rootIndex,0x000000,0,haffList);
	
		fprintf(outputFile,"haffCode List:\r\n");
		for(i=0;i<LENGTH-1;i++)
			fprintf(outputFile,"%d,",haffList[i].haffCode);
		fprintf(outputFile,"%d\r\n",haffList[i].haffCode);
		
		fprintf(outputFile,"haffCode List Len:\r\n");
			for(i=0;i<LENGTH-1;i++)
			fprintf(outputFile,"%d,",haffList[i].haffCodeLen);
		fprintf(outputFile,"%d\r\n",haffList[i].haffCodeLen);

	 }

/*	for(i=0;i<=8;i++)
		fprintf(outputFile,"%d\t",getBinLen(i));
*/
 }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -