Question: In C, how would i add linear probing to handle collisions in the following code? #include #include #define HASH_TABLE_SIZE 1057 typedef struct Entry Entry, *EntryPtr;

In C, how would i add linear probing to handle collisions in the following code?

#include

#include

#define HASH_TABLE_SIZE 1057

typedef struct Entry Entry, *EntryPtr;

struct Entry {

char * string;

int key;

int count;

};

Entry hash_table[HASH_TABLE_SIZE];

int key = 0;

int hashCode(int key) {

return key % HASH_TABLE_SIZE;

}

void add(char * tag)

{

Entry *item = (struct Entry*) malloc(sizeof(struct Entry));

item->string = tag;

item->key = key;

//get the hash

int hashIndex = hashCode(key);

//move in array until an empty or deleted cell

while(hash_table[hashIndex].count != 0) {

//go to next cell

++hashIndex;

//wrap around the table

hashIndex %= HASH_TABLE_SIZE;

}

hash_table[hashIndex] = *item;

key ++;

item->count ++;

printf("Inserted %s into the hash table. ", tag);

}

void display() {

int i = 0;

printf(" The has table contents are: ");

for(i = 0; i

printf(" (%d -> %s) ",hash_table[i].key, hash_table[i].string);

}

printf(" ");

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!