目录

DSA - 线性搜索(Linear Search)

线性搜索是一种非常简单的搜索算法。 在这种类型的搜索中,逐个对所有项目进行顺序搜索。 检查每个项目,如果找到匹配项,则返回该特定项目,否则搜索将继续,直到数据收集结束。

线性搜索动画

算法 (Algorithm)

Linear Search ( Array A, Value x)
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

伪代码 (Pseudocode)

procedure linear_search (list, value)
   for each item in the list
      if match item == value
         return the item's location
      end if
   end for
end procedure

要了解C编程语言中的线性搜索实现,请click-here

↑回到顶部↑
WIKI教程 @2018