| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2294 人关注过本帖
标题:有关哈夫曼树初始化问题
只看楼主 加入收藏
桑榆
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2015-6-29
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:6 
有关哈夫曼树初始化问题
for(i=1;i<=n;i++)    //对叶子节点初始化。
    {
        printf("输入第%d个字符基本信息:",i);
        scanf("%c,%d",&HT[i].data,&HT[i].weight);  第4行
        HT[i].parent=0;                            第5行
        HT[i].lchild=0;                            第6行
        HT[i].rchild=0;                            第7行
    }

在第4行到第7行依次出现了一下一样的问题,求解答???
 error C2228: left of '.data' must have class/struct/union type
 error C2228: left of '.weight' must have class/struct/union type
 error C2228: left of '.parent' must have class/struct/union type
 error C2228: left of '.lchild' must have class/struct/union type
 error C2228: left of '.rchild' must have class/struct/union type
搜索更多相关主题的帖子: 信息 叶子 
2015-06-29 23:50
林月儿
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:湖南
等 级:版主
威 望:138
帖 子:2277
专家分:10647
注 册:2015-3-19
收藏
得分:20 
HT[i].parent=NULL;                            第5行
        HT[i].lchild=NULL;                            第6行
        HT[i].rchild=NULL;                            第7行
    }

剑栈风樯各苦辛,别时冰雪到时春
2015-06-30 08:39
桑榆
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2015-6-29
收藏
得分:0 
啊!谢谢,不过我这个程序又出现了新的问题。我把生成的哈弗曼编码存入一位数组cd[]中,然后利用函数Strcpy()将一维数组复制给二维数组tco[][]的第i行,即tco[i][],请问调用函数的时候可不可以这样:Strcpy(tco[i][],cd);
但是就出现这样的错误了,这是怎么回事啊???
Status Strcpy(char tco[i][CODINGMAX],char cd[CODINGMAX])    //将求得的编码放入二维数组tco[][]中。改:cd。
{
    int j;
    for(j=1;cd[j]!='\0';j++)
        tco[i][j]=cd[j];
    return OK;
}
f:\哈夫曼编码器译码器\hfmcoding\string.h(6) : error C2065: 'i' : undeclared identifier
f:\哈夫曼编码器译码器\hfmcoding\string.h(6) : error C2057: expected constant expression
f:\哈夫曼编码器译码器\hfmcoding\string.h(6) : error C2466: cannot allocate an array of constant size 0
string.cpp
f:\哈夫曼编码器译码器\hfmcoding\string.h(6) : error C2065: 'i' : undeclared identifier
f:\哈夫曼编码器译码器\hfmcoding\string.h(6) : error C2057: expected constant expression
f:\哈夫曼编码器译码器\hfmcoding\string.h(6) : error C2466: cannot allocate an array of constant size 0
f:\哈夫曼编码器译码器\hfmcoding\string.cpp(31) : error C2057: expected constant expression
f:\哈夫曼编码器译码器\hfmcoding\string.cpp(31) : error C2466: cannot allocate an array of constant size 0
2015-06-30 09:34
林月儿
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:湖南
等 级:版主
威 望:138
帖 子:2277
专家分:10647
注 册:2015-3-19
收藏
得分:0 
f:\哈夫曼编码器译码器\hfmcoding\string.h(6) : error C2065: 'i' : undeclared identifier
变量i没有声明
 for(j=1;cd[j]!='\0';j++)
        tco[i][j]=cd[j];
    return OK;
f:\哈夫曼编码器译码器\hfmcoding\string.cpp(31) : error C2057: expected constant expression
f:\哈夫曼编码器译码器\hfmcoding\string.cpp(31) : error C2466: cannot allocate an array of constant size 0
31行的代码看不到,不能解释

剑栈风樯各苦辛,别时冰雪到时春
2015-06-30 11:55
桑榆
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2015-6-29
收藏
得分:0 
它是这样的:
13行:    Status Strcpy(char tco[i][CODINGMAX],char cd)    //将求得的编码放入二维数组tco[][]中。#define CODINGMAX 30
          {   
              int j;
16行:        for(j=1;cd[j]!='\0';j++)
                  tco[i][j]=cd[j];
              return OK;
          }
f:\哈夫曼编码器译码器\hfmcoding\string.cpp(13) : error C2057: expected constant expression
f:\哈夫曼编码器译码器\hfmcoding\string.cpp(13) : error C2466: cannot allocate an array of constant size 0
f:\哈夫曼编码器译码器\hfmcoding\string.cpp(16) : error C2109: subscript requires array or pointer type
f:\哈夫曼编码器译码器\hfmcoding\string.cpp(17) : error C2109: subscript requires array or pointer type
main.cpp

在调用这个函数的时候是这样的:
134行:  Strcpy(tco[i][],cd);    //将求得的编码放入二维数组tco[i][]中。
f:\哈夫曼编码器译码器\hfmcoding\coding.cpp(134) : error C2059: syntax error : ']'

在定义的时候是这样的:
30行:  Status Strcpy(char tco[i][CODINGMAX],char cd);    //将求得的编码放入二维数组tco[][]中。
f:\哈夫曼编码器译码器\hfmcoding\string.h(30) : error C2065: 'i' : undeclared identifier
f:\哈夫曼编码器译码器\hfmcoding\string.h(30) : error C2057: expected constant expression
f:\哈夫曼编码器译码器\hfmcoding\string.h(30) : error C2466: cannot allocate an array of constant size 0

嗯!!总的来说应该是二维数组调用时候参数的问题!!我想直接把二维数组tco[][]的第i行传入函数。但是好像不太会
2015-06-30 12:27
林月儿
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:湖南
等 级:版主
威 望:138
帖 子:2277
专家分:10647
注 册:2015-3-19
收藏
得分:0 
回复 5楼 桑榆
一点点的代码,无能为力。楼主好自为之

剑栈风樯各苦辛,别时冰雪到时春
2015-06-30 12:31
桑榆
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2015-6-29
收藏
得分:0 
,还是谢谢版主了!
2015-06-30 20:29
快速回复:有关哈夫曼树初始化问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012414 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved