Question: For this assignment you will be writing a C program that creates and uses a hash table. Your program will load a file of words
For this assignment you will be writing a C program that creates and uses a hash table. Your program will load a file of words into a hash table, support searching for a word, and returning the line numbers containing that word.
All assignment submissions will be validated using the class VM
Program Requirements
Below are the requirements for your program.
Hash table implementation
Hash table must implement separate chaining
Use a linked list for each node see below
typedef struct Node
char key;
int value;
struct Node next;
Node;
Static bucket array of size see below
#define BUCKETSIZE
typedef struct
Node bucketBUCKETSIZE;
int slotsused; Number of used bucket elements slots used in the hash table
int nodesused; Number of nodes used in the hash table
int maxnodes; Maximum number of nodes used by a slot in the hash table
HashTable;
Required functions
You project must include and implement the following function prototypes. You may include other functions if needed.
unsigned int hashconst char key;
The hash function uses the key, and calculates and returns the bucket index value. The source code for this function is provided later in the project.
void initializeHashTable ht;
The initialize function sets all bucket values to NULL, and slotsused, nodesused, and maxnodes to
Node createNodeconst char key int value;
The createNode function uses dynamic memory to create a new Node, and assign the new Node properties: key, value, next. Ensure dynamic memory allocation works, or output "Failed to allocate memory for new node.".
void insertHashTable ht const char key int value;
The insert function calls hash to create a bucket index, and createNode to create a new Node, and addappend the Node to the linked list associated with the bucket index. You will also need to updateslotsused, nodesused, and maxnodesappropriately
void getHashTable ht const char key int results int count;
The get function uses the key parameter to set the results parameter to an array of line numbers that match the key, and set the count parameter to the number of returned line numbers.
void freeHashTableHashTable ht;
The freeHashTable function frees all memory used by the hash table.
float calculateLoadFactorHashTable ht;
The calculateLoadFactor calculates and returns the hash table load factor slotsused BUCKETSIZE
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
