Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Programming Languages 12th International Symposium Dbpl 2009 Lyon France August 2009 Proceedings Lncs 5708

Authors: Philippa Gardner ,Floris Geerts

2009th Edition

3642037925, 978-3642037924

More Books

Students also viewed these Databases questions

Question

What advice would you provide to Jennifer?

Answered: 1 week ago

Question

What are the issues of concern for each of the affected parties?

Answered: 1 week ago