#define KEY_SIZE 10
#define TABLE_SIZE 13
#define equal(e1,e2) (!strcmp(e1.key,e2.key))
typedef struct{
char key[TABLE_SIZE];
}element;
typedef struct ListNode{
element item;
struct ListNode* link;
}ListNode;
ListNode* hash_table[TABLE_SIZE];
void hash_chain_add(element item, ListNode* ht){
int hash_value = hash_function(item.key);
ListNode* ptr;
ListNode* node_before = NULL;
ListNode* node = ht[hash_value];
for(; node; node_before = node , node=node->link){
if(equal(node->item,item)){
fprintf(stderr,"이미 탐색 키가저장되어 있음\n");
return;
}
}
ptr=(ListNode*)malloc(sizeof(ListNode));
ptr->item = item;
ptr->link = NULL;
if(node_before)
node_before->link = ptr;
else
ht[hash_value] = ptr;
}
void hash_chain_find(element item, ListNode* ht){
ListNode* node;
int hash_value = hash_function(item.key);
for(node=ht[hash_value];node;node=node->link){
if(equal(node->item,item)){
printf("키를 찾았음\n");
return;
}
}
printf("키를 찾지 못함\n");
}