X Tutup
#include using namespace std; int n = 10; int arr[10] = {7, 5, 9, 0, 3, 1, 6, 2, 4, 8}; int main(void) { for (int i = 0; i < n; i++) { int min_index = i; // 가장 작은 원소의 인덱스 for (int j = i + 1; j < n; j++) { if (arr[min_index] > arr[j]) { min_index = j; } } swap(arr[i], arr[min_index]); // 스와프 } for(int i = 0; i < n; i++) { cout << arr[i] << ' '; } }
X Tutup