From f36e69d20ffd1609d9c7407cc80ed1d650d3fc8e Mon Sep 17 00:00:00 2001 From: huihut Date: Fri, 9 Mar 2018 22:41:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A1=BA=E5=BA=8F=E6=9F=A5?= =?UTF-8?q?=E6=89=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 3 ++- Algorithm/SequentialSearch.h | 8 +++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index f30c192..914dae3 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "xstring": "cpp", "xtree": "cpp", "xutility": "cpp", - "iosfwd": "cpp" + "iosfwd": "cpp", + "vector": "cpp" } } \ No newline at end of file diff --git a/Algorithm/SequentialSearch.h b/Algorithm/SequentialSearch.h index bef7ced..28fd335 100644 --- a/Algorithm/SequentialSearch.h +++ b/Algorithm/SequentialSearch.h @@ -1,9 +1,7 @@ // 顺序查找 int SequentialSearch(vector& v, int k) { - int i = 0; - for (; i < v.size(); ++i) - if (v[i] == k) + for (int i = 0; i < v.size(); ++i) + if (v[i] == k) return i; - if (i == v.size()) - return -1; + return -1; } \ No newline at end of file