• 大小: 1.1MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-11-18
  • 语言: C/C++
  • 标签: 文本文件  Huffman  C++  

资源简介

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.embed.manifest
     文件         472  2018-01-02 23:19  combined\combined\Debug\combined.exe.embed.manifest.res
     文件         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\link-cvtres.read.1.tlog
     文件           2  2018-01-02 23:25  combined\combined\Debug\link-cvtres.write.1.tlog
     文件           2  2018-01-02 23:25  combined\combined\Debug\link.2692-cvtres.read.1.tlog
     文件           2  2018-01-02 23:25  combined\combined\Debug\link.2692-cvtres.write.1.tlog
     文件           2  2018-01-02 23:25  combined\combined\Debug\link.2692.read.1.tlog
     文件           2  2018-01-02 23:25  combined\combined\Debug\link.2692.write.1.tlog
     文件           2  2018-01-02 23:25  combined\combined\Debug\link.6724-cvtres.read.1.tlog
     文件           2  2018-01-02 23:25  combined\combined\Debug\link.6724-cvtres.write.1.tlog
     文件           2  2018-01-02 23:25  combined\combined\Debug\link.6724.read.1.tlog
     文件           2  2018-01-02 23:25  combined\combined\Debug\link.6724.write.1.tlog
............此处省略34个文件信息

评论

共有 条评论