c语言哈夫曼压缩文本,哈夫曼文本压缩C语言实现.doc
/*文件中有些參數定義的比較大,主要是為了適應較大文件的壓縮*/
#include
#include
#include
#include//用以刪除多余的中間文件
#define M 100000000000//最大字符數
int op,co[100];//編碼表的掃描指針,簡易棧co[]
typedef struct Hfnode //哈弗曼樹結點類型
{
int data;//權值域
char zimu;//存儲字母
struct Hfnode *Lson,*Rson,*next;//兒子鏈域和森林鏈域
}Hfnode,*Hfptr;
typedef struct snode//靜態數組結點類型
{
char c;//字符
int f1;//頻度
}snode;
typedef struct Lnode//編碼表結點類型
{
char c;
struct Lnode *next;
}Lnode,*Lptr;
void gotoxy(int x,int y){
COORD coord;
coord.X=x;
coord.Y=y;
SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), coord );
}
void paint1()
{
int i,j;
for(j=0;j<4;j++)
{for(i=0;i<70;i++)//簡易畫線代碼,呵呵
putchar(95);
putchar(10);putchar(10);putchar(10);
}
gotoxy(0,4);
printf("請輸入需打開的文件路徑:");
gotoxy(0,7);
printf("請輸入壓縮文件的保存路徑:");
gotoxy(0,10);
printf("此次文件壓縮率為:");
gotoxy(0,13);
}
void paint2()
{
int i,j;
for(j=0;j<4;j++)//畫4行直線
{for(i=0;i<70;i++)//簡易畫線代碼,呵呵
putchar(95);
putchar(10);putchar(10);putchar(10);
}
gotoxy(0,4);
printf("請輸入解壓文件的路徑:");
gotoxy(0,7);
printf("請輸入還原文件的保存路徑:");
gotoxy(0,10);
printf("還原結果:");
}
int putdata(Lptr strhead)//輸入函數
{
Lptr p;
FILE*fp;
int i=0;
char infile[30];
p=strhead;
gotoxy(0,5);
scanf("%s",infile);
if((fp=fopen(infile,"rb"))==NULL)
{
printf("文件打開錯誤!\n");
exit(0);
}
while(!feof(fp))
{
p->c=fgetc(fp)&0xFF;
p->next=new Lnode;
p=p->next;
/*putchar(ch[i]);*/
i++;
}
putchar(10);
fclose(fp);
return(i-1);
}
int stat(Lptr p,snode ch2[],int num)//統計函數
{
int i,j,last=0;
for(i=0;i
{
for(j=0;ch2[j].c!=p->c&&j!=last;)
j++;
if(j==last)
{
ch2[j].c=p->c;
ch2[j].f1=1;
last++;
}
else ch2[j].f1++;
p=p->next;
}
return(last);
}
void order(snode ch2[],int n)//冒泡排序
{
int i,j,k,t;
char a;
for(i=0;i
{
k=i;
for(j=i+1;j
if(ch2[j].f1
if(k!=i)
{
t=ch2[i].f1;
a=ch2[i].c;
ch2[i].c=ch2[k].c;
ch2[i].f1=ch2[k].f1;
ch2[k].c=a;
ch2[k].f1=t;
}
}
}
Hfptr i
總結
以上是生活随笔為你收集整理的c语言哈夫曼压缩文本,哈夫曼文本压缩C语言实现.doc的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php从网页获得数据,php根据URL获
- 下一篇: c语言位运算+乘法,关于c语言中的位运算