#define MAXSIZE 1000
typedef struct node {
int key;
int value;
struct node* next;
}node;
typedef struct hashTable {
node* data[MAXSIZE];
}hashTable;
int hash(int key){
return key % MAXSIZE;
}
void insert(hashTable* ht, int key, int value){
node* p = (node*)malloc(sizeof(node));
p->key = key;
p->value = value;
p->next = NULL;
int h = hash(key);
if (ht->data[h] == NULL) {
ht->data[h] = p;
}
else {
node* q = ht->data[h];
while (q->next != NULL) {
q = q->next;
}
q->next = p;
}
}
int search(hashTable* ht, int key) {
int h = hash(key);
if (ht->data[h] == NULL)
return -1;
else {
node* p = ht->data[h];
while (p != NULL) {
if (p->key == key)
return p->value;
p = p->next;
}
return -1;
}
}