Duplicates in Hash Table

Hey guys,

I am having problems with this function:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
bool HashTable::insert(char const * const key, const Player& aPlayer)
{
	//calculate the insertion position (the index of the array)
	size_t index = calculateIndex(key);

	for(int i=0; i < capacity; i++)
	{
		if(strcmp(key, table[i]->item.GetName()) == 0)
		{
			return false;
		}
		else
		{
			//create a new node to hold data
			node * newNode = new node(aPlayer);

			//insert the new node at the beginning of the linked list
			newNode->next = table[index];
			table[index] = newNode;
			size++;
			return true;
		}
	}
}


The inserting part works just fine, but the checking for duplicates where I compare the two values is crashing my program.

Any help or tips will be very much appreciated.

Thank you.
I just found a solution.

Instead of implementing the search and add into one function, I just made another function that just deals with finding. Then I called the find() in my insert() and if the result was true, don't add, else add.
Topic archived. No new replies allowed.