단순 선택 정렬은 가장 작은 요소부터 선택해 알맞은 위치로 옮겨서 순서대로 정렬하는 알고리즘입니다.
// straight selection sort algorithm implementation in C
#include <stdio.h>
#include <stdlib.h>
#define swap(type, x, y) do { type temp = x; x = y; y = temp; } while (0)
// Straight selection sort function
void straight_selection_sort(int* arr, int n) {
for (int i = 0; i < n - 1; i++) {
int min_index = i; // 현재 위치를 최소값 인덱스로 설정
for (int j = i + 1; j < n; j++) {
if (arr[j] < arr[min_index]) {
min_index = j; // 더 작은 값을 찾으면 최소값 인덱스 업데이트
}
}
if (min_index != i) {
swap(int, arr[i], arr[min_index]); // 최소값과 현재 위치의 값 교환
}
}
}