mirror of
https://github.com/huihut/interview.git
synced 2024-03-22 13:10:48 +08:00
修改选择排序模板实现
This commit is contained in:
parent
a70cd27f93
commit
f07406ea34
6
.vscode/settings.json
vendored
6
.vscode/settings.json
vendored
|
@ -12,6 +12,10 @@
|
|||
"tuple": "cpp",
|
||||
"system_error": "cpp",
|
||||
"xtr1common": "cpp",
|
||||
"limits": "cpp"
|
||||
"limits": "cpp",
|
||||
"exception": "cpp",
|
||||
"fstream": "cpp",
|
||||
"map": "cpp",
|
||||
"utility": "cpp"
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
if(i != min)
|
||||
std::swap(arr[i], arr[min]);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user