資源描述:
《費(fèi)諾和香農(nóng)編碼源程序及運(yùn)行結(jié)果.doc》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在學(xué)術(shù)論文-天天文庫。
1、香農(nóng)編碼源程序#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<<"請輸入信源符號(hào)個(gè)數(shù):";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<<"輸入錯(cuò)誤,請重新運(yùn)行";}}費(fèi)諾編碼源程序#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<<"輸入信源符號(hào)個(gè)數(shù)"<>n;cout<<"輸入各信源符號(hào)概率"<