Code:
int hdo_tt(hashtab h,type key,int index)
{
int i;
for(i=index+1;i<hashsize;++i)
if(h[i] && !strcmp(h[i]->key,key)) return i;
else if(!h[i]) return -1;
for(i=0;i<index;++i)
if(h[i] && !strcmp(h[i]->key,key)) return i;
else if(!h[i]) return -1;
return -1;
}
void hchen(hashtab h,type key,int val)
{
node *ptr=(node *)malloc(sizeof(node));
int index=hgetindex1(key);
if(h[index])
{ index=hgetindex2(key);
if(h[index])
{ index=hemptyfind(h,index);
if(index==-1)
{ printf("Loi:bang bam da day, khong chen duoc!\n");
return;
}
}
}
ptr->key=strdup(key);
ptr->val=val;
h[index]=ptr;
printf("h[%d]=%s.\n",index,key);
}