hashing with linear probing(if it collides)

what is the problem with my code? pls help...



int ss; // global variable


int hash::hfunction(int item){

int loc;
loc = item % 10;
return(loc);


};

int hash::linear(int item){


ss=ss+1;
int loc2;
loc2 = (item + ss) % 10;

if (checking(loc2)){
cout<<"\n"<<loc2<<endl;
return(loc2);

}
else {

linear(item);

}



};


bool hash::checking(int loc2){

if (hitem[loc2]==NULL)
{
return true;

}

else {

return false;
}



};

void hash::insert(int item){

int location;
location = hfunction(item);
// hfunction(item);
node* newnode = new node;
newnode->data = item;
newnode->next = NULL;


if(hitem[location]==NULL){
hitem[location] = newnode;
return;
}
else if (hitem[location]!=NULL){

location = linear(item);


hitem[location] = newnode;
return;
// cout<<"\n"<<location<<endl;
}



node* temp = hitem[location];
while(temp!=NULL){
if(temp->next == NULL){
temp->next = newnode;
return;
}
temp = temp->next;
}
};



void hash::display(){
for(int i=0; i<10; i++){
cout<<"\narray "<<i<<" ";
node* temp = hitem[i];
while(temp!=NULL){
cout<<temp->data<<" ";
temp = temp->next;
}
cout<<"\n";
}
code tags please!!!!!!!!½! + explaining what the code should do if we dont know what it should do we cant help you! sry but for now you need to figure out by yourself!
Topic archived. No new replies allowed.