Skip to content

Commit

Permalink
修改选择排序模板实现
Browse files Browse the repository at this point in the history
  • Loading branch information
huihut committed Mar 29, 2018
1 parent a70cd27 commit f07406e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
"tuple": "cpp",
"system_error": "cpp",
"xtr1common": "cpp",
"limits": "cpp"
"limits": "cpp",
"exception": "cpp",
"fstream": "cpp",
"map": "cpp",
"utility": "cpp"
}
}
8 changes: 5 additions & 3 deletions Algorithm/SelectionSort.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ void SelectionSort(vector<int>& v) {
// 模板实现
template<typename T>
void Selection_Sort(std::vector<T>& arr) {
for (int i = 0; i < arr.size() - 1; i++) {
int len = arr.size();
for (int i = 0; i < len - 1; i++) {
int min = i;
for (int j = i + 1; j < arr.size(); j++)
for (int j = i + 1; j < len; j++)
if (arr[j] < arr[min])
min = j;
std::swap(arr[i], arr[min]);
if(i != min)
std::swap(arr[i], arr[min]);
}
}

0 comments on commit f07406e

Please sign in to comment.