91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 11KB
    文件類型: .c
    金幣: 1
    下載: 1 次
    發(fā)布日期: 2021-08-04
  • 語言: C/C++
  • 標(biāo)簽:

資源簡介

哈夫曼編碼及譯碼,可以查看編碼后的二進(jìn)制文件,可以打印生成的哈夫曼樹,還可以譯碼,提供菜單選項(xiàng),根據(jù)提示鍵入大寫字母進(jìn)行相應(yīng)的操作

資源截圖

代碼片段和文件信息

#include?
#include?
#include?


struct?bitree
{
????char?c;//字符
????int?num;//對應(yīng)字符的個(gè)數(shù)
????int?flag;//標(biāo)記位,先定義為1,在輸出直觀二叉樹時(shí)使用
????struct?bitree?*parent;
????struct?bitree?*rchild;
????struct?bitree?*lchild;
};
//二叉樹節(jié)點(diǎn)信息
struct?data
{
????char?c;//字符
????int?num;//對應(yīng)字符的個(gè)數(shù)
????int?x[26];//對應(yīng)字符的哈夫曼編碼
}a[26];
//字符信息
struct?stack
{
????struct?bitree?*t;//二叉樹節(jié)點(diǎn)指針
????struct?stack?*next;
};
//構(gòu)造二叉樹的入棧出棧操作
int?inputdata()
{
????FILE?*input;
????char?ch;
????char?infile[10];
????printf(“please?enter?the?filenamewhich?will?save?the?characters:“);
????scanf(“%s“infile);
????input=fopen(infile“w“);
????printf(“please?enter?a?string?of?charactersend?with?#:“);
????getchar();
????ch=getchar();
????while(ch!=‘#‘)
????{
????????fputc(chinput);
????????ch=getchar();
????}
????fclose(input);
????return?0;
}
//輸入需要編碼的數(shù)據(jù),保存在文件中
struct?stack?*?pushstack(struct?stack?*hdstruct?stack?*?tpstruct?bitree?*p)
{
????struct?stack?*q;
????int?t=p->num;
????q=(struct?stack?*)malloc(sizeof(struct?stack));
????if(q==NULL)
????{
????????printf(“false!“);
????????exit(0);
????}
????q->t=p;
????q->next=NULL;
????if(tp->next==NULL)
????{
????????q->next=tp;
????????tp=q;
????????return?tp;
????}
????if(t<=tp->t->num)
????{
????????q->next=tp;
????????tp=q;
????????return?tp;
????}
????struct?stack?*s=tp;
????while(s->next!=hd)
????{
????????if(t>s->next->t->num)
????????s=s->next;
????????else
????????break;
????}
????q->next=s->next;
????s->next=q;
????return?tp;
}
//各個(gè)字符按從大到小的順序依次入棧
struct?stack?*?statistics(struct?stack?*hdstruct?stack?*tp)
{
????char?ch;
????int?i;
????char?filename[10];
????struct?bitree?*p;
????FILE?*output;
????printf(“please?enter?the?filenamewhich?save?the?characters:“);
????scanf(“%s“filename);
????output=fopen(filename“r“);
????if(output==NULL)
????{
????????printf(“cannot?open?the?file!“);
????????exit(0);
????}
????for(i=0;i<26;i++)
????a[i].num=0;
????while(!feof(output))
????{
????????ch=fgetc(output);
????????if(ch>=97&&ch<=122)
????????{
????????????for(i=97;i<=122;i++)
????????????if(ch==i)
????????????{
????????????????a[i-97].c=ch;
????????????????a[i-97].num++;
????????????????break;
????????????}
????????}
????}
????fclose(output);
????for(i=0;i<26;i++)
????if(a[i].num)
????printf(“(%c%d)?“a[i].ca[i].num);
????for(i=0;i<26;i++)
????if(a[i].num)
????{
????????p=(struct?bitree?*)malloc(sizeof(struct?bitree));
????????if(p==NULL)
????????{
????????????printf(“false!“);
????????????exit(0);
????????}
????????p->c=a[i].c;
????????p->flag=1;
????????p->num=a[i].num;
????????p->lchild=p->parent=p->rchild=NULL;
????????tp=pushstack(hdtpp);
????}
????return?tp;
}
//分析文件中的字符,并且入棧
struct?stack?*popstack(struct?stack?*top)
{
????struct?stack?*p;
????p=top->next;
????free(top);
????top=p;
????return?top;
}
//出棧操作,構(gòu)造二叉樹時(shí)使用
struct?stack?*?inittree(struct?stack?*headstruct?st

評論

共有 條評論