c - 顺序搜索算法的问题

标签 c sequential

另外,为什么这会因为我使用 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/

相关文章:

c - 有效评估 max(a,b) 内部循环 c.f.分支预测?

c - 在 C 中读/写结构到 fifo

c - 在 8 秒内检测 16 GB 笔式驱动器上的内容更改

c - C 中带有指向其他结构数组指针的结构的问题

MySQL 连续连续行字段,即使在删除和插入时也是如此

arrays - R:如何在数组中查找非顺序元素

python - Keras: "must compile model before using it"尽管使用了 compile()

c - 在 C 中解析 Twitter 提要

web-services - 如何使用 AngularJS 进行顺序 Rest Web 服务调用?

java - Android - 异步网络调用 - 相互依赖的响应