#include <stdio.h>
#include <string.h>
#include <iomanip.h> //参数化输入\输出
#include <stdlib.h>
#include <conio.h>
//using namespace //名称空间
#define TOTAL 40 //39个关键字
#define MAXLEN 10 //关键字长度
#define HASHLEN 41 //哈希表长度41
#define M 40
typedef struct //哈希表 结构体
{
char keyword[MAXLEN]; //关键字
int count; //记录频度
int con; //记录冲突次数
}HASH;
//全局变量
int cont=0; //统计关键词个数
char KeyWords[TOTAL][MAXLEN]={ "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"}; //C语言中的39个关键字存入二维数组中,排好序的数组
HASH HS[HASHLEN]; //建立结构体HS
//函数声明
void Show(int key);
int Read(char *filename);
int isLetter(char ch);
int isKeyWords(char *word);
int FindHX(char *keyword);
int CreatHX(char *keyword);
int GetFreePos(int key);
int GetKey(char *keyword);
void main()
{
char orz;
int flag=1,i,count,key,has;
char filename[128],word[MAXLEN];
while(flag)
{
printf("\t\tA.读取一个文件\n");
printf("\t\tB.输出Hash表(关键字总数,冲突次数)\n");
printf("\t\tC.查询某关键字在Hash表中的情况\n");
printf("\t\tD.显示Hash表中的冲突关键字\n");
printf("\t\tE.显示C语言关键字的Ha
哈希表实现的统计关键字频度
最新推荐文章于 2023-02-08 13:17:34 发布
该程序实现了一个哈希表结构,用于统计C语言关键字在文件中的出现频率。通过读取文件,识别关键字并利用哈希函数计算位置,解决冲突。用户可以选择读取文件、查看哈希表、查询关键字、显示冲突关键字等功能。
摘要由CSDN通过智能技术生成