提交 f36e69d2 编写于 作者: 辉哈's avatar 辉哈

修改顺序查找

上级 b43c794c
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
"xstring": "cpp", "xstring": "cpp",
"xtree": "cpp", "xtree": "cpp",
"xutility": "cpp", "xutility": "cpp",
"iosfwd": "cpp" "iosfwd": "cpp",
"vector": "cpp"
} }
} }
\ No newline at end of file
// 顺序查找 // 顺序查找
int SequentialSearch(vector<int>& v, int k) { int SequentialSearch(vector<int>& v, int k) {
int i = 0; for (int i = 0; i < v.size(); ++i)
for (; i < v.size(); ++i) if (v[i] == k)
if (v[i] == k)
return i; return i;
if (i == v.size()) return -1;
return -1;
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册