用哈希表实现C语言关键字的算法

来源:百度知道 编辑:UC知道 时间:2024/05/19 04:16:49
利用Hash技术统计某个C源程序中的关键字出现的频度
扫描一个C程序,用Hash表存储该程序中出现的关键字,并统计该程序中的关键字出现的频度,用线性探测法解决Hash冲突。设Hash函数为
Hash(Key)=[(Key第一个字符在1-26个字母中的序号)*100+(Key最后一个字符在1-26个字母中的序号)%41

#include <iostream.h>
#include<fstream.h>
#include <string>
#include <iomanip.h>
using namespace std;

const int TOTAL=32;
const int MAXLEN=10;
const int HASHLEN=41;
int cont=0;
class HashTable
{
public:
char keyword[MAXLEN];
int count;
int num;
};
HashTable HS[HASHLEN];

char KeyWords[TOTAL][MAXLEN]= {
"char", "double", "enum", "float", "int", "long", "short", "signed",
"struct", "union", "unsigned", "void", "break", "case", "continue",
"default", "do", "else", "for", "g