資源簡介
1、對文本信源,尋求最佳壓縮方案,現完整的無失真壓縮的編譯碼算法,完成對文本文件的壓縮及解壓。 2、構建性能分析模塊,實現對信源熵的統計、壓縮后的傳輸率(bits/symbol),以及恢復文本的完整情況進行分析。

代碼片段和文件信息
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#define?OK?1
#define?ERROR?0
struct?node
{
????long?weight;
????unsigned?char?ch;
????int?parentlchildrchild;
????char?code[256];
????int?Length;
}huffmannode[512];
int?compress();
int?uncompress();
int?select(struct?node?*nodeint?n);
int?coding(struct?node?*nodeint?n);
int?main()
{
????int?choice;
printf(“*************************************************************************\n“);
printf(“*******************************電子科學學院******************************\n“);
printf(“*****************************信息理論與編碼******************************\n“);
printf(“***********************無失真信源編碼*游程+Huffman碼*********************\n“);
printf(“***************************徐櫻笑、張巍燁、孫權**************************\n“);
printf(“*************************************************************************\n“);
????printf(“please?choose?the?operation:\n“);
????printf(“1.compress?file\n“);
????printf(“2.uncompress?file\n“);
????printf(“3.exit\n“);
????scanf(“%d“&choice);
????if(choice==1)compress();
????else?if(choice==2)uncompress();
????else?if(choice==3)return?0;
????else?printf(“ERROR!\n“);
????return?0;
}
int?select(struct?node?*nodeint?n)//找出兩個無父節點且權值最低的結點
{
????int?i;
????int?s;
????long?min=214748364;
????for(i=0;i<=n;i++)
????{
????????if(node[i].parent!=-1)continue;
????????if(node[i].weight ????????{
????????????min=node[i].weight;
????????????s=i;
????????}
????}
????return?s;
}
int?coding(struct?node*nodeint?n)//哈弗曼編碼
{
????int?begin;
????int?ifc;
????char?codes[256];
????codes[n-1]=‘\0‘;
????for(i=0;i ????{
????????begin=n-1;
????????for(c=if=node[i].parent;f!=-1;c=ff=node[f].parent)
????????{
????????????begin--;
????????????if(node[f].lchild==c)
????????????????codes[begin]=‘0‘;
????????????else
????????????????codes[begin]=‘1‘;
????????}
????????strcpy(node[i].code&codes[begin]);
????????node[i].Length=strlen(node[i].code);
????}
????return?OK;
}
int?compress()//壓縮
{
????int?countnmjis1s2;
????char?infile[20]outfile[20]ch1=0ch2=0ch=‘#‘codes[256];
????unsigned?char?c;
????FILE?*ifp*ofp1*ofp;
????long?Filelength=0filelength=0lengenth=0ff;
????double?time;
????float?ratespeed;
????clock_t?beginfinish;
????printf(“please?input?the?path?and?the?name?of?the?source?file:“);
????scanf(“%s“infile);
????ifp=fopen(infile“rb“);
????if(ifp==NULL)
????{
????????printf(“Not?found!\n“);
????????return?ERROR;
????}
????ofp1=fopen(“C:\\Users\\Administrator\\Documents\\pythonexercise\\untitled\\c\\combined\\combined\\combined\\1.txt““wb“);
????printf(“please?input?the?path?and?the?name?of?the?object?file:“);
????scanf(“%s“outfile);
????ofp=fopen(outfile“wb“);
????if(ofp==NULL)
????{
????????printf(“Not?found!\n“);
????????return?ERROR;
????}
????begin=clock();
????while(!feof(ifp
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-02-05?21:27??combined\
?????目錄???????????0??2018-02-05?21:27??combined\Debug\
?????文件???????40448??2018-01-02?23:25??combined\Debug\combined.exe
?????文件??????352220??2018-01-02?23:25??combined\Debug\combined.ilk
?????文件??????445440??2018-01-02?23:25??combined\Debug\combined.pdb
?????目錄???????????0??2018-02-05?21:27??combined\combined\
?????文件????????6599??2018-01-02?23:27??combined\combined\1.txt
?????文件????????4411??2018-01-02?23:29??combined\combined\2.txt
?????目錄???????????0??2018-02-05?21:26??combined\combined\Debug\
?????文件????????6768??2018-01-02?23:25??combined\combined\Debug\CL.read.1.tlog
?????文件????????2408??2018-01-02?23:25??combined\combined\Debug\CL.write.1.tlog
?????文件????????2490??2018-01-02?23:25??combined\combined\Debug\cl.command.1.tlog
?????文件?????????406??2017-12-30?10:16??combined\combined\Debug\combined.exe.em
?????文件?????????472??2018-01-02?23:19??combined\combined\Debug\combined.exe.em
?????文件?????????381??2018-01-02?23:25??combined\combined\Debug\combined.exe.intermediate.manifest
?????文件?????????171??2018-01-02?23:28??combined\combined\Debug\combined.lastbuildstate
?????文件????????1106??2018-01-02?23:28??combined\combined\Debug\combined.log
?????文件???????36368??2018-01-02?23:25??combined\combined\Debug\combined.obj
?????文件?????????713??2017-12-30?10:14??combined\combined\Debug\combined.vcxprojResolveAssemblyReference.cache
?????文件???????????0??2017-12-30?10:14??combined\combined\Debug\combined.write.1.tlog
?????文件?????????206??2017-12-30?10:16??combined\combined\Debug\combined_manifest.rc
?????文件???????????2??2018-01-02?23:25??combined\combined\Debug\li
?????文件???????????2??2018-01-02?23:25??combined\combined\Debug\li
?????文件???????????2??2018-01-02?23:25??combined\combined\Debug\li
?????文件???????????2??2018-01-02?23:25??combined\combined\Debug\li
?????文件???????????2??2018-01-02?23:25??combined\combined\Debug\li
?????文件???????????2??2018-01-02?23:25??combined\combined\Debug\li
?????文件???????????2??2018-01-02?23:25??combined\combined\Debug\li
?????文件???????????2??2018-01-02?23:25??combined\combined\Debug\li
?????文件???????????2??2018-01-02?23:25??combined\combined\Debug\li
?????文件???????????2??2018-01-02?23:25??combined\combined\Debug\li
............此處省略34個文件信息
評論
共有 條評論