Having trouble in inserting a node in the linked list. The Linked List *p is not NULL always ,therefore I am unable to see the data[index] is NULL or NOT.
created a class for node,linked list and hash table. Problem is that to avoid collisions I am unable to find the data[index} is NULL,where Linked list* data[].
void add(const value_type& val) {
int index = 0;
index = hashfun(val);
LinkedList<value_type>* p = data[index];
if(p!=NULL) //ALways p is !=NULL is the problem
{
data[index]->add_L(val);
}
else
data[index] = new LinkedList<value_type>();
data[index]->addToHead(val);
}
Find whether the data[index] is empty.
Aucun commentaire:
Enregistrer un commentaire