永发信息网

tc提示 Declaration syntax error

答案:1  悬赏:50  手机版
解决时间 2021-04-30 21:27
  • 提问者网友:骑士
  • 2021-04-30 12:35

void HuffmanCoding(HuffmanTree &HT(此处提示Declaration syntax error), HuffmanCode HC[], int *w, int n) {

int i, j;

char *cd;

int p;

int cdlen;

if (n<=1) return;

m = 2 * n - 1;

HT = (HuffmanTree)malloc((m+1) * sizeof(HTNode)); for (i=1; i<=n; i++) { HT[i].weight=w[i-1];

HT[i].parent=0;

HT[i].lchild=0;

HT[i].rchild=0;

}

for (i=n+1; i<=m; i++) { HT[i].weight=0;

HT[i].parent=0;

HT[i].lchild=0;

HT[i].rchild=0;

}

puts("\n哈夫曼树的构造过程如下所示:");

printf("HT初态:\n 结点 weight parent lchild rchild");

for (i=1; i<=m; i++)

printf("\n%4d%8d%8d%8d%8d",i,HT[i].weight,

HT[i].parent,HT[i].lchild, HT[i].rchild);

printf(" 按任意键,继续 ...");

getchar();

for (i=n+1; i<=m; i++) { Select(HT, i-1);

HT[s1].parent = i; HT[s2].parent = i;

HT[i].lchild = s1; HT[i].rchild = s2;

HT[i].weight = HT[s1].weight + HT[s2].weight;

printf("\nselect: s1=%d s2=%d\n", s1, s2);

printf(" 结点 weight parent lchild rchild");

for (j=1; j<=i; j++)

printf("\n%4d%8d%8d%8d%8d",j,HT[j].weight,

HT[j].parent,HT[j].lchild, HT[j].rchild);

printf(" 按任意键,继续 ...");

getchar();

}

cd = (char *)malloc(n*sizeof(char)); p = m; cdlen = 0;

for (i=1; i<=m; ++i) HT[i].weight = 0;

while (p) {

if (HT[p].weight==0) {

HT[p].weight = 1;

if (HT[p].lchild != 0) { p = HT[p].lchild; cd[cdlen++] ='0'; }

else if (HT[p].rchild == 0) { HC[p] = (char *)malloc((cdlen+1) * sizeof(char));

cd[cdlen] ='\0'; strcpy(HC[p], cd); }

} else if (HT[p].weight==1) { HT[p].weight = 2;

if (HT[p].rchild != 0) { p = HT[p].rchild; cd[cdlen++] ='1'; }

} else { // HT[p].weight==2,HT[p].weight = 0; p = HT[p].parent; --cdlen;

}

}

} // HuffmanCoding

最佳答案
  • 五星知识达人网友:佘樂
  • 2021-04-30 13:42
HuffmanTree &HT这个是C++的声明方式,你的Tc是Tc2.0吧,它是用C语法的,所以这个声明会出错,你可以改成HuffmanTree *HT,这样应该可以了
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯