Dear friends,

hello to you all as this is my first thread - question to the forum.

This is my problem, which is a school exersize:

I create a linked list which contains three numbers r,c,d per node

From this list I have to create a hash table htable[7] with hash function
hk=d mod 7

my idea of doing it is through the following code, where htable and fnl are hash tables and curr is a structure of the same type.

while (curr != NULL)
	{
		if (htable[hk]==NULL) {
			htable[hk]=curr;
			fnl[hk]=curr;
		}
		else {
			fnl[hk]->next=curr;
			fnl[hk]=curr;
		}
	curr=curr->next;

doing it what I get as a result is that each of the linked lists of the htable have all the correct nodes AND all the rest of the nodes of the initial linked list from the node the htable should end to the end of the list.

Is any one able to explain why is that happening and how should it be adressed?

Thanks a lot in advance for your time and effort!!!

Could you provide the exact text of the whole exercise?

let me do this for you,as it seems that we have the same exercise with cuckas. we have a structure struct *cell {int row, int column, int distance, struct cell *next}. Row and column refer to the position of a pawn on a game table. Distance refers to the distance that the pawn may have fro its original position. So, we re asked to find the possible positions that the pawn can move to. By calling a function, this strust *cell is filled with numbers and we finally have something like that:
6 4 0
5 4 0
6 4 1
4 4 2
5 5 2 and so on...As i mentioned earlier,the third number is the distance.So we have to create a hash table struct cell *htable[7]. We have to use distance (d) as the key and the hash function will be h(k)= d mod7. In case of collision we must use the method of hash table with chaining.
All in all,we must write a function QHashTable that will take the elements of the list (by giving it a pointer that refers to the first node) and make the desired hash table. We are also requested to write another function,called QHashTableDisplay that will use the hash table that we created and print the number of nodes that every hash table position has. I hope that you can help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.