Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create c a program that stores words in a Hash Table and then searches for the words. Requirements You will keep track of words that

Create c a program that stores words in a Hash Table and then searches for the words.

Requirements You will keep track of words that are 20 or fewer characters long. The nodes that you will create as structs will contain an array of char of length 21 and a pointer to the next node. Call this struct WordNode.

In main, declare an array variable to contain your hash table. Let the array buckets contain pointers to WordNodes. The size of the array is 11.

Create a loop that gets one word at a time from the user until they enter "." as the only thing on the input line.

Each time you get a word, pass the word as a parameter to a hash function. This hash function must call the djb2 function (from the sample code below and change the parameter to work with chars rather than unsigned chars) and then use the Division Method to return a value between 0 and 10 (inclusive) as a hash value. Use this returned hash value to determine which bucket should contain the word. Then add the word to the bucket as described in lecture. Make sure that your linked lists are sorted linked lists, sorted in ascending order (e.g. "alpha" would occur before "theta"). They do not have to have a tail or prev pointers but they can if you want (the tail pointer would now have to be in the bucket along with the head pointer).

Once the user is done entering words, set up a separate loop to get input for words to search for. Then search for the words in the hash table by determining the appropriate bucket and searching the linked list found there (if there is one). Every time you do a comparison in your search, use printf() (or cout) to display the word you are comparing your search word against. When you find the word, use printf() to display "Success!". If you don't find the word, use printf() to display "Not there!". This will continue in a loop until the user enters "." as the only thing on the input line.

You should comment as normal.

Call your primary source file mini3.c. Put your linked list code into linkedList.c (or linkedList.h if you use a class). Put your djb2 and hash functions into djb2.c. Put any other code into your already-existing mini3.c. You can create any .h files you need in order to support this but do not create any other .c files.

this is the hash function djb2 (Created by Dan Bernstein) unsigned long hash(unsigned char *str) { unsigned long hash = 5381; int c = 0; while ((c = *str++) != \0) hash = ((hash << 5) + hash) + c; return hash; }

no extra files or functions are neee

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

Genetic Databases

Authors: Martin J. Bishop

1st Edition

ISBN: 0121016250, 978-0121016258

More Books

Students also viewed these Databases questions

Question

b. Where did they come from?

Answered: 1 week ago

Question

c. What were the reasons for their move? Did they come voluntarily?

Answered: 1 week ago

Question

5. How do economic situations affect intergroup relations?

Answered: 1 week ago