#include #include #define NMAX 100; enum functionType { INTEGER_CAST, COMPONENT_SUM; }; typedef struct node_type { long int key; struct node_type *next; } NodeT; void insertCell(NodeT **bucketList, int hashCode, long int value) { NodeT *p = (NodeT *) malloc(sizeof(NodeT)); NodeT *q; if (bucketList[hashCode] == NULL) { p->key = value; p->next = NULL; bucketList[hashCode] = p; } else { q = find(p->key); if (q == NULL) { // it's not in the bucket list, insert it p->next = bucketList[hashCode]; bucketList[hashCode] = p; } else resolveConflict(p, q); } } NodeT *find(NodeT **bucketList, int type, int key) { int hashCode; NodeT *p; if (type == INTEGER_CAST) { hashCode = integerCast(key); } else { hashCode = componentSum(key); } p = bucketList[hashCode]; while (p != NULL) { if (p->key == key) return p; p = p->next; } return NULL; } void printHashTable(NodeT **bucketList) { int i; NodeT *p; for (i = 0; i < NMAX; i++) { if (bucketList[i] != NULL) { printf("Bucket for hash value %d: ", i); p = bucketList[i]; while (p != NULL) { printf("ld ", p->key); p = p->next; } printf("\n"); } } } void deleteHashTable(NodeT **bucketList, int type, long int value) { int hashCode; NodeT *p, *temp; if (type == INTEGER_CAST) { hashCode = integerCast(value); } else hashCode = componentSum(value); if (bucketList[hashCode] != NULL) { if (bucketList[hashCode]->key == value) { // first element p = bucketList[hashCode]; bucketList[hashCode] = p->next; free(p); return 1; } else { // look for the required element and delete it if it exists while (p->next->key != value) p = p->next; if (p != NULL) { temp = p->next; p->next = temp->next; free(temp); return 1; } } } // Nothing deleted. return 0; } int main() { NodeT *intCastTable[NMAX], *compSumTable[NMAX]; return 0; }