#include<stdio.h>
#define MAX_SIZE 10
#define SWAP(x, y, t) ((t) = (x), (x) = (y), (y) = (t))
int list[MAX_SIZE] = { -25,23,4,5,-77,43,97,18,96,-95 };
void prn_sort(int list[], int n);
void selection_sort(int list[], int n);
void main() {
int n = MAX_SIZE;
printf("\n-----정렬 전 데이터-----\n");
prn_sort(list, n);
selection_sort(list, n);
printf("\n-----정렬 후 데이터-----\n");
prn_sort(list, n);
}
void selection_sort(int list[], int n) {
printf("\n-----선택 정렬 시작-----\n");
int i, j, least, temp;
for (i = 0; i < n - 1; i++) {
least = i;
for (j = i + 1; j < n; j++)
if (list[j] < list[least])
least = j;
SWAP(list[i], list[least], temp);
printf("%d단계 : ", i + 1);
prn_sort(list, n);
}
/*
for (i = 0; i < n - 1; i++) {
for (j = i + 1; j < n; j++) {
if (list[i] > list[j]) {
SWAP(list[i], list[j], temp);
}
}
printf("%d단계 : ", i + 1);
prn_sort(list, n);
}
*/
printf("-----선택 정렬 종료-----\n");
}
void prn_sort(int list[], int n) {
for (int i = 0; i < n; i++)
printf("%d ", list[i]);
printf("\n");
}