河南理工大学课程设计报告书
}
}
//判断新生成的后缀码是否已在集合F里,不在则加入F集合 if(comparing(Fh,cp_temp->string)) { }
FP->next=cp_temp; FP=FP->next;
void main() {
//功能提示和程序初始化准备
cout<<\唯一可译码的判断!\\n\struct strings Cstr,*Ch, *CP,*tempPtr;
Ch=&Cstr;
CP=Ch;
Fh=&Fstr;
FP=Fh; char c[]=\
Ch->string=new char[strlen(c)]; strcpy(Ch->string, c); Ch->next=NULL; char f[]=\
Fh->string=new char[strlen(f)]; strcpy(Fh->string, f); Fh->next=NULL; //输入待检测码的个数
int Cnum;
cout<<\输入待检测码的个数:\cin>>Cnum;
10
河南理工大学课程设计报告书
cout<<\输入待检测码\for(int i=0; i { cout<>tempstr; CP->next=new (struct strings); CP=CP->next; CP->string=new char[strlen(tempstr)] ; strcpy(CP->string, tempstr); CP->next = NULL; } outputstr(Ch); CP=Ch; while(CP->next->next) { CP=CP->next; tempPtr=CP; do { tempPtr=tempPtr->next; houzhui(CP->string,tempPtr->string); }while(tempPtr->next); } outputstr(Fh); struct strings *Fbegin,*Fend; Fend=Fh; while(1) { if(Fend == FP) 11 河南理工大学课程设计报告书 { } Fbegin=Fend; Fend=FP; CP=Ch; cout<<\是唯一可译码码组!\exit(1); while(CP->next) { CP=CP->next; } tempPtr=Fbegin; for(;;) { } tempPtr=tempPtr->next; houzhui(CP->string,tempPtr->string); if(tempPtr == Fend) break; outputstr(Fh);//输出F集合中全部元素 } } 2、香农编码 #include public: T() {} ~T(); void Create(); 12 河南理工大学课程设计报告书 void Coutpxj(); void Coutk(); void Coutz(); void Print(); protected: int n; double *p; double *pxj; int *k; double *mz; }; void T::Create() { cout<<\请输入信源符号个数:\ cin>>n; p=new double[n]; cout<<\请分别输入这\个概率:\\n\ for(int i=0;i mz=new double[n]; double sum=0.0; for(i=0;i for(i=0;i int k=i; for(int j=i+1;j T::~T() { 13 河南理工大学课程设计报告书 delete p; delete pxj; delete k; delete mz; } void T::Coutpxj() { pxj[0]=0; for(int i=1;i pxj[i]=0; for(int j=0;j void T::Coutk() { for(int i=0;i double d=(-1)*(log(p[i])/log(2)); if(d-(int)d>0) k[i]=(int)d+1; else k[i]=(int)d; } } void T::Print() { cout<<\ < for(int i=0;i < if(2*mz[i]-1>=0) { 14 河南理工大学课程设计报告书 cout<<1; mz[i]=2*mz[i]-1; } else { cout<<0; mz[i]=2*mz[i]; } } cout< double K=0.0,H=0.0,Y; for(i=0;i K+=(double)p[i]*k[i]; H+=(-1)*p[i]*(log10(p[i])/log10(2.0)); } Y=H/K; cout<<\平均码长:\ cout<<\信源熵:\ cout<<\编码效率:\ } void main() { T t;int e; try { t.Create(); t.Coutpxj(); t.Coutk(); t.Print(); } catch(int e) {if(e==1) cout<<\输入错误,请重新运行\} 15 百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库信息论与编码课程设计(3)在线全文阅读。
相关推荐: