题目内容

阅读下列函数说明和C代码,将应填入 (n) 处的字句写在对应栏内。[说明]HufTman树又称最优二叉树,是一类带权路径长度最短的树,在编码中应用比较广泛。构造最优二叉树的Huffman算法如下:①根据给定的n各权值{W1,w2,…,wn)构成n棵二叉树的集合F={T1,T2,…,Tn},其中每棵树Ti中只有一个带权为wi的根节点,其左右子树均空。②在F中选取两棵根节点的权值较小的树作为左右子树,构造一棵新的二叉树,置新构造二叉树的根节点的权值为其左右予树根节点的权值之和。③从F中删除这两棵树,同时将新得到的二叉树加入到F中。重复②③,直到F中只剩一棵树为止。函数中使用的预定义符号如下:#define INT MAX 10000#define ENCODING LENGTH 1000typedef enum(none,left_child,right_child) Which;/*标记是左孩子还足右孩子*/typedef char Elemtype;typedef struct TNode{//Huffman树节点Elemtype letter;intweight; //权值int parent; //父节点Which sigh;char *code; //节点对应编码}HTNode,*HuffmanTree;int n;char coding[50];//储存代码[函数]void Select(HuffmanTree HT,int end,int *sl,int *s2)/*在0~END之间,找出最小和次小的两个节点序号,返吲S1、S2*/{int i;int min 1=INT_MAX;int min 2=INT_MAX;for(i=0;i<=end;i++){/*找最小的节点序号*/if(( (1) )&&(HT[i].weight<minl)){*s1=i;min 1=HT[i].weight;}}for(i=0;i<=end;i++){/*找次小节点的序号*/if((HT[i].parent==0)&&( (2) )&&(min 2>HT[i].weight)){*s2=i;min 2=HT[i].weight;}}}void HuffmanTreeCreat(HuffmanTree&HT)/*建立HUFFMAN树*/{int i;int m=2*n-1;int s1,s2;for(i=n;i<m;i++){Select( (3) );HT[s1].parent=i;HT[s2].parent=i;HT[s1].sigh=left child;HT[s2].sigh=right child;HT[i].weight= (4) ;}}void HuffmanTreeEncoding(char sen[],HuffmanTree HT){ /*将句子进行编码*/int i=0;int j;while(sen[i] !=’\0’){for(j=0;j<n;j++){if(HT[j].letter==sen[i])(/*字母吻合则用代码取代*/strcat(coding, (5) );break;}}i++;if (Sen [1]==32) i++;}printf("\n%s",coding);} (5)处填()。

查看答案
更多问题

Questions 21 to 23 are based on the following news. At the end of the news item, you will be given 15 seconds to answer the questions. Now listen to the news How long has Burma’s military been in power

A. For more than 30 years.
B. For more than 20 years.
C. For more than 50 years.
D. For more than 40 years.

阅读以下说明和C代码,将应填入 (n) 处的字句写在对应栏内。[说明]函数combine(a,b,c)是计算两个整数的组合数。由于计算结果可能超出10ng整型的可表示范围,故采用数组方式存储,例如:k位长整数m用数组c[]存储结构如下:m=c[k]×10k-1+c[k-1]×10k-2+…+c[2]×10+c[1],利用c[0]存储长整数m的位数,即c[0]=k。数组的每个元素只存储长整数m的一位数字,长整数运算时,产生的中间结果的某位数字可能会大于9,这是就应该调用format将其归整,使数组中的每个元素始终只存储长整数的一位数字。整数a和b(a>b)的组合数为:,其中u1=a,u2]=a-1,…,ub=a-b+1,d1=1,d2=2,…,db=b。为了计算上述分式,先从u1,u2,…,ub中去掉d1×d2×…×db的因子,得到新的u1,u2,…,ub,然后再将它们相乘。[函数]#define NAXN 100int gcd(int a,int b)//求两个整数a和b的最大公因子{if(a<b){intC=a;a=b;b=c;}for(inti=b;i>=2;i--){if( (1) )return i;}return 1;void format(int *a)//将长整数数组归整{int i;for(i=1;i<a[0]||a[i]>=10;i++){if(i>=a[0]) (2) ;a[i+1]+=a[i]/10;a[i]=a[i]%10;}if(i>a[0]) (3) ;}void combine(int a,int b,int *C){int i,J,k,x;int d[MAXN],u[MAXN];k=0;for(i=a;i>=a-b+1;i--)u[++k]=i;u[0]=b;for(i=1;i<=b;i++)d[i]=i;for(i=1;i<=u[0];i++){//从u中各元素去掉d中整数的因子for(j=1;j<=b;j++){x=gcd(u[i],d[j]);//计算最大公约数u[i]/=X;d[j]/=x;}(4) ;C[1]=1;//长整数c初始化for(i=1;i<=u[0];i++)(//将u中各整数相乘,存于长整数c中if(u[i]!=1){for(j=1;j<=c[0];j++){C[j]= (5) ;}format(C);//将长整数c归整}}} (2)处填()。

Question 30 is based on the following news. At the end of the news item, you will be given 5 seconds to answer the question. Now listen to the news.

A. Japanese auto-makers promised to stop dumping cars in the US
B. the Government promised to solve the US-Japan trade imbalance
C. three US companies have ended the US Japan trade imbalance
D. Japan agreed to sell cars at the agreed prices inside the US

______是企业中最稳定的因素,它足企业永恒的财富。

答案查题题库