cpp-interview/Algorithm/SequentialSearch.h

9 lines
167 B
C
Raw Normal View History

2018-02-11 01:08:43 +08:00
// 顺序查找
int SequentialSearch(vector<int>& v, int k) {
int i = 0;
for (; i < v.size(); ++i)
if (v[i] == k)
return i;
if (i == v.size())
return -1;
}