void List::searchInterpolation(int id){
Node* low = head;
Node* mid;
Node* high = tail;
int lowest = 0;
int middle;
int highest = getLength()-1;
int counter = 0;
while (low->getDato()->getId() <= id && high->getData()->getId() >= id){
middle = lowest + (id - low->getData()->getId()) * (highest - lowest) /
(high->getData()->getId() - low->getData()->getId());
while (middle != counter){
mid = low->getNext();
counter++;
if (mid->getData()->getId() < id){
low = mid;
} else if (mid->getData()->getId() > id){
high = mid;
} else{
cout <<"1"<<endl;
}
if (low->getData()->getId() == id){
cout<<"1"<<endl;
} else{
cout<<"-1"<<endl;
}
}
}
}
嗯,这就是我想出的。我已经测试过了,似乎有一个无限循环。它开始给我 -1 和 1 无处不在。