I need to implement an interpolation search on a linked list, I have some code but I'm getting errors whenever I search anything that isn't the first element. Even if the element I'm searching for is in the list, if it isn't the first one it returns a -1.
int ListaS::interpolationSearch(int id){
NodoS* low = head;
NodoS* mid = low;
NodoS* 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());
getIndex(mid, middle);
if (mid->getData()->getId() < id)
{
low = mid;
}
else if (mid->getData()->getId() > id)
{
high = mid;
}
else
{
return 1;
}
if (low->getData()->getId() == id)
{
return 1;
}
else
{
return -1;
}
}
}