- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
利用哈希技术统计C源程序关键字出现的频度解析
东 华 理 工 大 学
课程设计实验 报 告
姓名 : 学号: 班级:
实验题目:数据结构课程设计之利用哈希技术统计C源程序关键字出现的频度
实验时间: 12月31日 实验地点:软件楼
一、实验目的
加深对数据结构的了解
实验内容
三、实验步骤
#include iostream
#include string
#include iomanip
using namespace std;
const int TOTAL=39; //39个关键字
const int MAXLEN=10; //关键字长度
const int HASHLEN=41; //哈希表长度
int cont=0; //统计哈希表中的关键字个数
char KeyWords[TOTAL][MAXLEN]= //构造二维数组存储39个关键字
{
asm,auto,break,case,cdecl,
char,const,continue,default,do,
double,else,enum,extern,far,
float,for,goto,huge,if,
int,interrupt,long,near,pascal,
register,return,short,signed,sizeof,
static,struct,switch,typedef,union,
unsigned,void,volatile,while,
};
int GetKey(char *keyword);
void menu();
void Select(int choice);
int Input();
int Read(char *filename);
void Show(int key);
int isLetter(char ch);
int FindHX(char *keyword);
int CreatHX(char *keyword);
int GetFreePos(int key);
int isKeyWords(char *word);
class HASH //哈希表类
{
public:
char keyword[MAXLEN];
int count; //出现次数(频度)
};
HASH HS[HASHLEN];
int main()
{
coutendl;
cout --数据结构课程设计之利用哈希技术统计C源程序关键字出现的频度--endl;
menu();
Select(Input());
return(0);
}
int GetKey(char *keyword) //哈西函数
{
return ( keyword[0]*100+keyword[strlen(keyword)-1] ) % 41; //Hash函数为:Hash(Key)=[(Key的首字母序号)*100+(Key的尾字母序号)] Mod 41
}
void menu()//主菜单函数
{
coutendl;
cout\t1.读取一个文件endl;
cout\t2.输出Hash表(关键字总数,冲突次数)endl;
cout\t3.回主菜单endl;
cout\t4.退出endl;
}
int Input()
{
coutendl;
cout请输入你的选择(1-4): ;
while(true) //确保输入的为数字
{
int choice=0;
if((cinchoice))
{
if((choice=0)||(choice4))
cout输入范围不正确,请重新输入endl;
}
else
{
cout输入错误,请重新输入endl;
cin.clear();
}
while(!isspace(cin.get())) //判断字符是否为空白符 当字符为空白符时,返回非零值,否则返回零。
continue;
coutendl;
return choice;
}
}
void Select(int choice)
{
char filename[128],word[MAXLEN];
int i,key,count;
switch(choice)
{
case 1:
cout请输入要读取的文件名(文件必须在同一目录下):;
cinfilename;
coutendl;
Read(filename);
Select(Input());
break;
case 2:
原创力文档


文档评论(0)