I'm building a simple hash table using division method with size as divisor (ie. key % size ) with separate chaining using doubly linked lists (so I have an array of pointers). Even for my bool is_duplicate function, it doesn't run, could this be an issue with need to pass ptrs to ptrs but I thought not needed since I thought we're updating just content of this array which in this case happens to be pointers (all initially NULL). I tried passing ptrs to ptrs but compiler complains...
#include <iostream>
usingnamespace std;
struct hockey_player
{
hockey_player* back;
hockey_player* next;
int num;//this is key
string team;
string name;
};
//this function ensures unique items inserted into hash table
bool is_duplicate(hockey_player* bucket, int cur_bucket, int num_, string team_, string name_ )
{
if ( !bucket[cur_bucket] )/**if empty list then item not a duplicate*/
returnfalse;
for ( hockey_player* cur = bucket[cur_bucket]; cur != NULL; cur = cur->next )
if ( cur->num == num_ && cur->team == team_ && cur->name == name_ )
returntrue;
returnfalse;
}
int main()
{
hockey_player* p_1 = NULL;
hockey_player* p_2 = NULL;
hockey_player* p_3 = NULL;
hockey_player* bucket[15] = {p_1, p_2, p_3};
//Manually insert first node and check if it's a duplicate (of course it shouldn't be), i'll write insert function afterwards...
hockey_player* newGuy_1 = new hockey_player;
newGuy_1->num = 2;
newGuy_1->team = "EDM";
newGuy_1->name = "Wayne Gretzky";
newGuy_1->back = NULL;
newGuy_1->next = NULL;
int size = 15;
int cur_bucket = newGuy_1->num % size;//hash key to an indx in bucket array (I know not good choice but I just want to get my bool is_duplicate function working...
bool isDuplicate = is_duplicate(bucket, cur_bucket, newGuy_1->num, newGuy_1-> team, newGuy_1->name );//program doesn't run, it complains about my bool is_duplicate function...I'm not sure how to fix this...
if ( !isDuplicate)
bucket[cur_bucket] = newGuy_1;
else
cout << "Item already in list!" << endl;
return 0;
}
Appreciate anyone's help. It seems so simple but I can't figure it out...
I was immature about my comment and it has been reported (by myself) and is removed. I apologize to the user so I hope someone can help out and not ostracize me. (cheers people)
My uncalled for comment (just being rude about calling user who started thread lazy) @ http://www.cplusplus.com/forum/general/74500/ has been removed.