#include <iostream>
using namespace std;
int main(){
int array[]={1,10,5,8,7,6,4,3,2,9};
for(int i=0; i<sizeof(array)/sizeof(int); i++){
int min=1000000;
int index=0;
for(int j=i; j<sizeof(array)/sizeof(int); j++){
if(min>array[j]){
min=array[j];
index=j;
}
}
if(index!=i){
int temp = array[index];
array[index]=array[i];
array[i]=temp;
}
}
for(int i=0; i<sizeof(array)/sizeof(int); i++){
cout<<array[i]<<" ";
}
cout<<endl;
system("pause");
return 0;
}
1 2 3 4 5 6 7 8 9 10
출처 :https://gmlwjd9405.github.io/2018/05/06/algorithm-selection-sort.html
[알고리즘] 선택 정렬(selection sort)이란 - Heee's Development Blog
Step by step goes a long way.
gmlwjd9405.github.io
2. 정렬의 개요와 선택 정렬(Selection Sort)
일반적으로 알고리즘을 공부할 때 가장 먼저 풀어보는 문제는 '정렬(Sort)' 문제입니다. 왜냐하면 정렬만...
blog.naver.com
'C++ 알고리즘 > 5. 정렬 알고리즘' 카테고리의 다른 글
버블 정렬 (시간복잡도 O(N^2) ) -가장 비효율적 (0) | 2019.09.01 |
---|---|
정렬 알고리즘 시간 복잡도 비교 (0) | 2019.09.01 |
댓글