void List::interpolationSearch(int id){
Node* low = head;
Node* mid = low;
Node* high = tail;
int lowest = 0;
int middle;
int highest = getLength()-1;
int counter = 0;
while (low->getData()->getId() <= id && high->getData()->getId() >= id){
middle = lowest + (id - low->getData()->getId()) * (highest - lowest) /
(high->getData()->getId() - low->getData()->getId());
while (middle != counter){
mid->setSig(low);
counter++;
if (mid->getData()->getId() < id){
low = mid;
} elseif (mid->getData()->getId() > id){
high = mid;
} else{
cout <<"1"<<endl;
}
if (low->getData()->getId() == id){
cout<<"1"<<endl;
} else{
cout<<"-1"<<endl;
}
}
}
That's what I've got, but it is not working, it is always printing -1 even when the element is in the list. I know using this kind of search is a dumb idea for linked list, it is going to be more inefficient than a sequential search but my college professor asked for it to be done.