#include "stdafx.h"
void swap(int *a,int *b)
{
int temp=0;
temp=*a;
*a=*b;
*b=temp;
}
int _tmain(int argc, _TCHAR* argv[])
{
const int total=10;
int data[80]={26,5,77,1,61,11,59,15,49,19};
int i=0,j=0,count=0,c_compare=0,c_exchange=0,min=9999,min_index=0;
printf("n[정렬전]",i);
for(count=0;count<total;count++)
printf("%2d ",data[count]);
printf("n");
for(i=0;i<(total-1);i++)
{
min=9999;
min_index=0;
for(j=i;j<total;j++)
{
if(data[j] < min)
{
min=data[j];
min_index=j;
}
}
swap(&data[i],&data[min_index]);
printf("n[%2d회전]",i+1);
for(count=0;count<total;count++)
printf("%2d ",data[count]);
}
printf("nn[정렬후]");
for(count=0;count<total;count++)
printf("%2d ",data[count]);
printf("n비교횟수:%d 교체회수:%d",c_compare,c_exchange);
return 0;
}
이 정렬의 특징은
오름차순이든 내림차순이든
앞에서 부터 ~ 좌르르르륵 정리해나간다는거
쉽게 말하면
n^2의 시간 복잡도를 가지고
젤 작은수를 고른다 min으로 집어넣음
min하고 첫번째 자리수 수하고 교환
그럼 젤 첫번째 자리에 젤 작은수 또는 젤 큰수가 들어가고
두번째 자릿수
역시 두번쨰 자릿수부터 젤 끝까지 비교비교 작은수를
두번째 자릿수 하고 교환
이런식으로 계속해서 ~ 정렬하는 식임