import java.util.Scanner;
public class selectionSearch {
static final int N=15;
static int search(int a[],int n,int x)
{
int i;
int f=-1;
for(i=0;i<n;i++)
{
if(x==a[i])
{
f=i;
break;
}
}
return f;
}
public static void main(String[] args)
{
int x,n,i;
int[] array = new int[N];
for(i=0;i<N;i++)
{
array[i]=(int)(100+Math.random()*(100+1));
}
System.out.println("the original number is :");
for(i=0;i<N;i++)
{
System.out.println(array[i]);
}
System.out.println("enter the number to look for");
Scanner input=new Scanner(System.in);
x=input.nextInt();
n=search(array,N,x);
if (n<0)
{
System.out.println("number not found");
}
else
{
System.out.println("the index of number is :"+(n+1));
}
}
}
Selction Search
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 全线飘红时,发现toolchain跟别人不一样,别人是gmake,我的是cmake,然后发现系统里找不到gmake...
- 相对于BFS,Uniform-Cost search相对的有策略性一点。BFS采取FIFO的形式进行搜索,这种形式...
- According to bfs, it is a search method to go through all...
- Given a target integer T and an integer array A, A is sor...