I'm making a hash table using a linked lists to handle collision. So I'm creating an array of "head" pointers to access each linked list. I can't figure out why I'm getting the error below:
error C2440: 'initializing' : cannot convert from 'LinkHash::ListNode' to 'LinkHash::ListNode *'
I commented **not working** next to the line the error is coming from.
hash.h file:
class LinkHash
{
private:
int numItems;
int N;
class ListNode
{
public:
int data;
ListNode* next;
ListNode() : next(0){};
ListNode(int value) : data(value), next(0){};
};
ListNode *table, *holder;
int hash(const int &val);
void expand();
void shrink();
public:
LinkHash();
~LinkHash();
double loadFactor();
void put(const int &val);
void remove(const int &val);
void print();
bool found(const int &val);
};
Relevant code from .cpp file:
LinkHash::LinkHash()
{
numItems = 0;
N = 8;
table = new ListNode[N];
for(int x = 0; x < N; x++){
table[x] = 0;
}
}
LinkHash::~LinkHash()
{
delete [] table;
}
int LinkHash::hash(const int &val)
{
return (2 * val + 5) % N;
}
bool LinkHash::found(const int &val)
{
ListNode *temp = table[hash(val)]; //**not working**
while(temp){
if(temp->data == val){
return true;
}else{
temp = temp->next;
}
}
return false;
}
Thanks for any help