404
![](https://img-blog.csdnimg.cn/direct/c4af8ebf215e4c018009361e65465975.png)
#include "allinclude.h" //DO NOT edit this line
void PrintKeys(HashTable ht, void(*print)(StrKeyType)){
/* 请调用形参中的print函数输出关键字 */
int n , i;
for (char c = 'A' ; c <= 'Z'; c++) {
n = (c - 'A') % ht.size;
i = n;
while((n + 1) % ht.size != i){
if(-1 != ht.rcd[n].tag && ht.rcd[n].key[0] == c)
print(ht.rcd[n].key);
n = (n + 1) % ht.size;
}
}
}
415
![](https://img-blog.csdnimg.cn/direct/41f5cbc367c34d7dbe5169777a2a44b5.png)
#include "allinclude.h" //DO NOT edit this line
int BuildHashTab(ChainHashTab &H, int n, HKeyType es[])
{ // Add your code here
int i , j , k;
HLink p , q , t;
j = 0;
H.size = NUM;//哈希表容量
H.count = 0;//哈希表记录个数
H.rcd = (HLink *)malloc(H.size*sizeof(HLink));//开辟空间
if(H.rcd == NULL) return UNSUCCESS;//开辟失败
for (i = 0 ; i < H.size ; i++)
{
H.rcd[i] = NULL;//置空
}
for (i = 0; i < n; i++)
{
p = (HLink)malloc(sizeof(HNode));
p->data = es[i];
k = Hash(H , p->data);//哈希函数计算地址
t = H.rcd[k];
while(t != NULL)
{
if(t->data == p->data){
j = 1;//标记存在
break;
}
t = t->next;
}
if(j == 0){
q = H.rcd[k];
p->next = q;
H.rcd[k] = p;
H.count++;
}else{
H.count++;
j = 0;
}
}
return SUCCESS;
}
430
![](https://img-blog.csdnimg.cn/direct/dcbfd949486f48a180c9f9ea9f47815e.png)
#include "allinclude.h"
int countConflics(LHashTable H)
{
Node** p=H.rcd;
int sum=0;
for(int i=0;i<H.size;i++)
{
int j=0;
Node *q=H.rcd[i];
while(q!=NULL)
{
j=1;
sum++;
q=q->next;
}
if(j==1)
{
sum--;
}
}
return sum; //Temporary code. Modify it if necessary.
}
435
![](https://img-blog.csdnimg.cn/direct/2cdd763b542c4f1c97251cbb084965be.png)
#include "allinclude.h"
Node* searchLHash(LHashTable H, KeyType key, int &c)
{
int p=H.hash(key,H.size);
c=0;
Node*np;
for(np=H.rcd[p];np!=NULL;np=np->next)
{
if(np->r.key==key)
{
return np;
}
c++;
}
return NULL; //Temporary code. Modify it if necessary.
}