⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 p1(!).cpp

📁 数据结构 数据结构数据结构 数据结构
💻 CPP
字号:
#include <stdio.h>
#include <time.h>
clock_t start, stop; 
double duration; 
int SequentialSearch(int A[], int N, int X);

void main ( )
{ 
	int n,temp,item, xx;
	unsigned long K=1200000;

	scanf("%d%d",&item,&xx); /*input the number of items of the array and the number searched*/ 

	K=K/item*10000;
	
	int Array[10000];
	for(n=0;n<item;n++) 
		Array[n] = n; /*set the value of each item of array*/
	
	start = clock(); 
	for(n=0;n<K;n++)
		SequentialSearch (Array,item,xx); 
	stop = clock(); /*Imply the function repeatly to obtain an accurate running time*/
	
	duration = ((double)(stop - start))/CLK_TCK;

	temp=SequentialSearch (Array,item,xx);
	
	if(temp!=-1)
		printf("%d\n%lu\n%e\n%e\n",temp,K,duration,duration/K);
	else
		printf("NotFound\n%lu\n%e\n%e\n",K,duration,duration/K);/*give the output*/
}





int
SequentialSearch(int A[], int N, int X)
{
	int i;
	for(i=0;i<N;i++){
		if (A[i]==X)
			return i; /*compare the number needed to be searched and each item of the array sequentially, 
						if matched, return the serial number*/ 
	}
	return -1; /*return -1 when not founded*/ 
}
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -