查看“︁线性搜索”︁的源代码
←
线性搜索
跳转到导航
跳转到搜索
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
在[[计算机科学]]中,'''线性搜索'''或'''顺序搜索'''是一种寻找某一特定值的[[搜索算法]],指按一定的顺序检查[[数组]]中每一个元素,直到找到所要寻找的特定值为止。是最简单的一种[[搜索算法]]。 ==分析== 假设一个数组中有<math> n </math>个元素,最好的情况就是要寻找的特定值就是数组里的第一个元素,这样仅需要1次比较就可以。而最坏的情况是要寻找的特定值不在这个数组或者是数组里的最后一个元素,这就需要进行<math> n </math>次比较。 ==實作範例== ===[[Julia (程式語言)]]=== <syntaxhighlight lang="julia"> # Julia Sample: LinearSearch function LinearSearch(A,Key) for i=1:length(A) if A[i]==Key return i end end return -1 end # Main Code A = [16,586,1,31,354,43,3] println(A) # Original Array println(LinearSearch(A,354)) # LinearSearch Array println(LinearSearch(A,43)) # LinearSearch Array println(LinearSearch(A,87)) # LinearSearch Array </syntaxhighlight> ==参考== *{{Translation/Ref|lang=en|article=Linear search|oldid=}} *{{cite book |last=Sahni |first=Sartaj |coauthors= |title= ''Data Structures,Algorithms,and Applications in C++'' |publisher= McGraw2-Hill |year= 1998 |month= |isbn= 978-7-11-07645-2 }} ==外部链接== * [http://www.paked.net/subject_pages/computer_science/prog5.htm C++ Program - Linear Search ] {{Wayback|url=http://www.paked.net/subject_pages/computer_science/prog5.htm |date=20160327062033 }} * [http://www15.brinkster.com/selvamselvam/linearsearch.html C Program - Linear Search Dead link ]{{dead link|date=2018年4月 |bot=InternetArchiveBot |fix-attempted=yes }} {{计算机小作品}} {{算法}} [[Category:搜尋演算法]]
该页面使用的模板:
Template:Cite book
(
查看源代码
)
Template:Dead link
(
查看源代码
)
Template:Translation/Ref
(
查看源代码
)
Template:Wayback
(
查看源代码
)
Template:算法
(
查看源代码
)
Template:计算机小作品
(
查看源代码
)
返回
线性搜索
。
导航菜单
个人工具
登录
命名空间
页面
讨论
不转换
查看
阅读
查看源代码
查看历史
更多
搜索
导航
首页
最近更改
随机页面
MediaWiki帮助
特殊页面
工具
链入页面
相关更改
页面信息