实验一 字典编码.docVIP

  • 4
  • 0
  • 约2.94千字
  • 约 5页
  • 2017-10-18 发布于河北
  • 举报
实验一 字典编码.doc

实验一 字典编码 一、实验题目 1、输入: ①The Lempel Ziv algorithm can compress the English text by about fifty five percent. ②The cat cannot sit on the canopy of the car. 2、输出:经过字典编码后生成的码字。 二、实验目的 1、理解和掌握字典编码的原理; 2、理解和掌握字典译码的原理。 三、算法设计 四、程序分析 1.用结构体存储字符串及其对应的字典编码; 2.用链表存储整个字典; 3.dictionary()子函数的作用是将当前字符同链表中的字典相比较,若存在与字典中,则向结构体的数组里存放发送信息的下一位,直到当前数组中的字符串和链表字典不相等则将该字符串存储到链表中,并将标号存储到加最后一位字符之前的字符串对应的结构体的code,更新字典。 4.main()函数主要是实现初始字典的构建,即’a’-’z’和’A’-’Z’的存储。 五、程序代码 子函数: #ifndef DICTIONARY_H_INCLUDED #define DICTIONARY_H_INCLUDED void dictionary(SLNode *head,int x1,char c1[],int num) { char c3[5]; DataType C2; int i; int flag=1,flag1=0,flag2=0,k=1; SLNode *p; printf(The message is:\n %s\n,c1); printf(The codeword is:\n); for(i=0;ix1;i=i+flag2) { c3[0]=c1[i]; c3[1]=\0; p=head; while(p-next!=NULL) { if(strcmp(c3,p-data.lable)) //c3与链表中的值不相等 { p=p-next; flag1=0; } else //c3与链表中的值相等 { c3[flag++]=c1[i+k]; k++; c3[flag]=\0; flag2=flag-1; flag1=1; printf(%d ,p-data.code); if(i+k=x1) break; continue; } } if(flag1==0) //插入新元素 { strcpy(C2.lable,c3); C2.code=num++; ListInsert(head,ListLength(head),C2); flag=1; flag1=1; k=1; memset(c3,0,5); } } printf(\n); p=head; printf(The dictionary is:\n); while(p-next!=NULL) { printf( %d -- 【%s】\n,p-next-data.code,p-next-data.lable); p=p-next; } } #endif // DICTIONARY_H_INCLUDED 主函数: #include stdio.h #include stdlib.h #include malloc.h #include string.h typedef struct { char lable[5]; int code; }DataType; #include list.h #include dictionary.h int main() { SLNode *head,*head1; Data

文档评论(0)

1亿VIP精品文档

相关文档