Files
2021-Postgraduate-408/Data-Structure/Sort/sorts/selectSort.cpp
2018-11-20 16:36:46 +08:00

21 lines
426 B
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include <iostream>
using namespace std;
int main(){
int a[] = {-1, 6, 5, 2, 8, 4, 1, 3, 7}; //为了和教材一致数组从第1位开始
int len = sizeof(a) / sizeof(a[0]);
for(int i = 1; i < len; i++){
int k = i;
for(int j = i + 1; j < len; j++){
if(a[j] < a[k]) k = j;
}
if(k != i){
int temp = a[i];
a[i] = a[k];
a[k] = temp;
}
}
for(int i = 1; i < len; i++)
cout << a[i];
return 0;
}