请输入您要查询的百科知识:

 

词条 线性查找
释义

在一列给定的值中进行搜索,从一端开始逐一检查每个元素,直到找到所需元素的过程。

线性查找又称为顺序查找

如果查找池是某种类型的一个表,比如一个数组,简单的查找方法是从表头开始,一次将每一个值与目标元素进行比较,最后,或者查找到目标,或者达到表尾,而目标不存在于组中,这个方法称为线性查找。

#include <iostream>

using namespace std;

int display(int [],int,int);

int main()

{

const int i=10;

int a[i];

int number;

for(int j=0;j <=i;j++)

a[j]=j*2;

for(int j=0;j <=i;j++)

cout < <a[j] < <' ';

cout < <"enter the number:";

cin>>number;

int result=display(a,i,number);

if(result==1)

cout < <"can find this number;" < <endl;

else

cout < <"number miss" < <endl;

system("pause");

return 0;

}

int display(int array[],int b,int conter)

{

for(int i=0;i <=b;i++)

{

if(array[i]==conter)

return 1;

}

return 0;

}

随便看

 

百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。

 

Copyright © 2004-2023 Cnenc.net All Rights Reserved
更新时间:2025/3/30 4:24:28