线性搜索(查找)

线性搜索(查找)是一个非常简单的搜索算法。在这种类型的搜索,顺序查找是由在所有项目一个接一个来的。 每一个项目一个一个地检查,如果找到匹配则特定数据项被返回,否则继续搜索,直到收集数据结束。

算法

Linear Search ( A: array of item, n: total no. of items ,x: item to be searched)
Step 1: Set i to 1
Step 2: if i > n then go to step 7
Step 3: if A[i] = x then go to step 6
Step 4: Set i to i + 1
Step 5: Go to Step 2
Step 6: Print Element x Found at index i and go to step 8
Step 7: Print element not found
Step 8: Exit

要查看C编程语言的线性搜索实现,请点击这里


上一篇: 队列优先级 下一篇: 线性搜索实例程序(C语言)