欢迎来到天天文库
浏览记录
ID:29116155
大小:58.50 KB
页数:7页
时间:2018-12-16
《费诺和香农编码源程序及运行结果.doc》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、香农编码源程序#include#include#include#includeclassT{public:T(){}~T();voidCreate();voidCoutpxj();voidCoutk();voidCoutz();voidPrint();protected:intn;double*p;double*pxj;int*k;double*mz;};voidT::Create(){cout<<"请输入信源符号个数:";cin>>
2、n;p=newdouble[n];cout<<"请分别输入这"<>p[i];pxj=newdouble[n];k=newint[n];mz=newdouble[n];doublesum=0.0;for(i=0;i3、i]=p[k];p[k]=m;}}}T::~T(){deletep;deletepxj;deletek;deletemz;}voidT::Coutpxj(){pxj[0]=0;for(inti=1;i0)k[i]=(int)d+1;elsek[i]=(int)4、d;}}voidT::Print(){cout<<"Xi"<5、f(2*mz[i]-1>=0){cout<<1;mz[i]=2*mz[i]-1;}else{cout<<0;mz[i]=2*mz[i];}}cout<6、in(){Tt;inte;try{t.Create();t.Coutpxj();t.Coutk();t.Print();}catch(inte){if(e==1)cout<<"输入错误,请重新运行";}}费诺编码源程序#include#include#defineN15intpa[N][N];voidfano(floatp[],inta[N][N],intn,intm,intk){floatg=0.0,h=0.0,d,b,c;inti,j,flase;if(n7、i=n;i<=m;i++){g=p[i]+g;}g=g/2;for(i=n;i<=m;i++){h=h+p[i];if(h>g){d=h-p[i];b=h-g;c=g-d;if(c>b){for(j=n;j<=i;j++)a[j][k]=0;fano(p,a,n,i,k+1);for(j=i+1;j<=m;j++)a[j][k]=1;fano(p,a,i+1,m,k+1);}else{for(j=n;j<=i-1;j++)a[j][k]=0;fano(p,a,n,i-1,k+1);for(j=i;j<=m;j++)8、a[j][k]=1;fano(p,a,i,m,k+1);}break;}}}}voidmain(){inti,j,k[N],n,flase=0;floatp[N],m,H=0.0,K=0.0,sum=0.0;cout<<"输入信源符号个数"<>n;cout<<"输入各信源符号概率"<
3、i]=p[k];p[k]=m;}}}T::~T(){deletep;deletepxj;deletek;deletemz;}voidT::Coutpxj(){pxj[0]=0;for(inti=1;i0)k[i]=(int)d+1;elsek[i]=(int)
4、d;}}voidT::Print(){cout<<"Xi"<5、f(2*mz[i]-1>=0){cout<<1;mz[i]=2*mz[i]-1;}else{cout<<0;mz[i]=2*mz[i];}}cout<6、in(){Tt;inte;try{t.Create();t.Coutpxj();t.Coutk();t.Print();}catch(inte){if(e==1)cout<<"输入错误,请重新运行";}}费诺编码源程序#include#include#defineN15intpa[N][N];voidfano(floatp[],inta[N][N],intn,intm,intk){floatg=0.0,h=0.0,d,b,c;inti,j,flase;if(n7、i=n;i<=m;i++){g=p[i]+g;}g=g/2;for(i=n;i<=m;i++){h=h+p[i];if(h>g){d=h-p[i];b=h-g;c=g-d;if(c>b){for(j=n;j<=i;j++)a[j][k]=0;fano(p,a,n,i,k+1);for(j=i+1;j<=m;j++)a[j][k]=1;fano(p,a,i+1,m,k+1);}else{for(j=n;j<=i-1;j++)a[j][k]=0;fano(p,a,n,i-1,k+1);for(j=i;j<=m;j++)8、a[j][k]=1;fano(p,a,i,m,k+1);}break;}}}}voidmain(){inti,j,k[N],n,flase=0;floatp[N],m,H=0.0,K=0.0,sum=0.0;cout<<"输入信源符号个数"<>n;cout<<"输入各信源符号概率"<
5、f(2*mz[i]-1>=0){cout<<1;mz[i]=2*mz[i]-1;}else{cout<<0;mz[i]=2*mz[i];}}cout<6、in(){Tt;inte;try{t.Create();t.Coutpxj();t.Coutk();t.Print();}catch(inte){if(e==1)cout<<"输入错误,请重新运行";}}费诺编码源程序#include#include#defineN15intpa[N][N];voidfano(floatp[],inta[N][N],intn,intm,intk){floatg=0.0,h=0.0,d,b,c;inti,j,flase;if(n7、i=n;i<=m;i++){g=p[i]+g;}g=g/2;for(i=n;i<=m;i++){h=h+p[i];if(h>g){d=h-p[i];b=h-g;c=g-d;if(c>b){for(j=n;j<=i;j++)a[j][k]=0;fano(p,a,n,i,k+1);for(j=i+1;j<=m;j++)a[j][k]=1;fano(p,a,i+1,m,k+1);}else{for(j=n;j<=i-1;j++)a[j][k]=0;fano(p,a,n,i-1,k+1);for(j=i;j<=m;j++)8、a[j][k]=1;fano(p,a,i,m,k+1);}break;}}}}voidmain(){inti,j,k[N],n,flase=0;floatp[N],m,H=0.0,K=0.0,sum=0.0;cout<<"输入信源符号个数"<>n;cout<<"输入各信源符号概率"<
6、in(){Tt;inte;try{t.Create();t.Coutpxj();t.Coutk();t.Print();}catch(inte){if(e==1)cout<<"输入错误,请重新运行";}}费诺编码源程序#include#include#defineN15intpa[N][N];voidfano(floatp[],inta[N][N],intn,intm,intk){floatg=0.0,h=0.0,d,b,c;inti,j,flase;if(n7、i=n;i<=m;i++){g=p[i]+g;}g=g/2;for(i=n;i<=m;i++){h=h+p[i];if(h>g){d=h-p[i];b=h-g;c=g-d;if(c>b){for(j=n;j<=i;j++)a[j][k]=0;fano(p,a,n,i,k+1);for(j=i+1;j<=m;j++)a[j][k]=1;fano(p,a,i+1,m,k+1);}else{for(j=n;j<=i-1;j++)a[j][k]=0;fano(p,a,n,i-1,k+1);for(j=i;j<=m;j++)8、a[j][k]=1;fano(p,a,i,m,k+1);}break;}}}}voidmain(){inti,j,k[N],n,flase=0;floatp[N],m,H=0.0,K=0.0,sum=0.0;cout<<"输入信源符号个数"<>n;cout<<"输入各信源符号概率"<
7、i=n;i<=m;i++){g=p[i]+g;}g=g/2;for(i=n;i<=m;i++){h=h+p[i];if(h>g){d=h-p[i];b=h-g;c=g-d;if(c>b){for(j=n;j<=i;j++)a[j][k]=0;fano(p,a,n,i,k+1);for(j=i+1;j<=m;j++)a[j][k]=1;fano(p,a,i+1,m,k+1);}else{for(j=n;j<=i-1;j++)a[j][k]=0;fano(p,a,n,i-1,k+1);for(j=i;j<=m;j++)
8、a[j][k]=1;fano(p,a,i,m,k+1);}break;}}}}voidmain(){inti,j,k[N],n,flase=0;floatp[N],m,H=0.0,K=0.0,sum=0.0;cout<<"输入信源符号个数"<>n;cout<<"输入各信源符号概率"<
此文档下载收益归作者所有