4️⃣ 顺序查找
#include <iostream>
#include <vector>
using namespace std;
int SequentialSearch (const vector<int> &a, int x){
for (int i=0; i!= a.size(); i++)
if(a[i]==x)
return i;
return -1;
}
int main(){
vector<int> a{3,6,0,7,1,2,9,4};
int x;
cin >> x;
if(SequentialSearch(a,x)<0)
cout << x << "不在数组a中!" << endl;
else
cout << x << "是a[" << SequentialSearch(a,x) << "]" << endl;
return 0;
}