順序搜索算法的麻煩 - Trouble with a sequential search algorithm -开发者知识库

順序搜索算法的麻煩 - Trouble with a sequential search algorithm -开发者知识库,第1张

Also why does this give me an error because I used bool?

另外,為什么這會給我一個錯誤,因為我使用bool?

I need to use this sequential search algorithm, but I am not really sure how. I need to use it with an array. Can someone point me in the correct direction or something on how to use this.

我需要使用這種順序搜索算法,但我不確定如何。我需要將它與數組一起使用。有人可以指出我正確的方向或如何使用它。

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]);
}

4 个解决方案

#1


1  

Looks like you'd use it like this...

看起來你會像這樣使用它......

// 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
}

最佳答案:

本文经用户投稿或网站收集转载,如有侵权请联系本站。

发表评论

0条回复