#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
/*顺序查找*/
int SequentialSearch(int* array, int n, int search);
int main(){
clock_t start, end;
int n = 100000;
cout << "共" << n << "个数据" << endl;
int array[100000];
for(int i = 0; i < n; i++){
array[i] = rand();
}
start = clock();
if(SequentialSearch(array, n, 5979) != -1)
cout << "找到了,在数组中下标是" << SequentialSearch(array, n, 5979) << endl;
end = clock();
cout << "用时:" << (end - start) << "ms" << endl;
return 0;
}
int SequentialSearch(int* array, int n, int search){
for(int i = 0; i < n; i++){
if(search == array[i]){
return i;
}
}
return -1;
}
c++数据结构与算法(4)——超级简单的顺序查找
最新推荐文章于 2023-09-10 01:44:23 发布