#define STR_SIZE 100
typedef struct Node{
char str[STR_SIZE]; // key为字符串
int row; // value为结果所在的行
struct Node * next;
} HashNode;
int hash(char * str, int size)
{
long h = 0;
for(int i = 0; i < strlen(str); i++){
h = (h * 26 % size + str[i] - 'a') % size; // 字符串的hashcode, 权为26是因为小写字母,不限制时为128,这样能够让结点尽可能分布均匀,减少地址冲突
// 取模是为了防止int型溢出
}
return h % size;
}
bool contain(HashNode * hashtable, char * str, int size)
{
HashNode *head = &hashtable[hash(str, size)];
HashNode *tail = head->next;
while(tail){
if(strcmp(tail->str, str) == 0) retur