另外,为什么这会因为我使用 bool 而给我一个错误?
我需要使用这种顺序搜索算法,但我不太确定如何使用。我需要将它与数组一起使用。有人可以指出我正确的方向或如何使用它吗?
bool seqSearch (int list[], int last, int target, int* locn){
int looker;
looker = 0;
while(looker < last && target != list[looker]){
looker++;
}
*locn = looker;
return(target == list[looker]);
}
最佳答案
看起来你会这样使用它......
// I assume you've set an int list[], an int listlen and an int intToFind
int where;
bool found = seqSearch(list, listlen - 1, intToFind, &where);
if (found)
{
// list[where] is the entry that was found; do something with it
}
关于c - 顺序搜索算法的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2763184/