#include <iostream> #include <iomanip> using namespace std;
const int MAX_ARY_SIZE = 10; void 선택출력 (int list[], int last); void 교환출력 (int list[], int current, int last);
int main (void) { int a,b,c,d,e,f,g,h,i,j,k; cout<<"난수의 숫자 10개를엔터로 구분하여 입력하세요"<<endl; cin>>a,b,c,d,e,f,g,h,j,k; int ary[ MAX_ARY_SIZE ] = {a,b,c,d,e,f,g,h,j,k};
cout << "정렬되지 않은 배열: "; for (i = 0; i < MAX_ARY_SIZE; i++) cout << setw(3) << ary[i];
선택출력 (ary, MAX_ARY_SIZE - 1); cout << "\n정렬된배열: "; for (i = 0; i < MAX_ARY_SIZE; i++) cout << setw(3) << ary[i]; cout << endl; return 0; } void 선택출력 (int list[], int last) { for (int current = 0; current < last; current++) 교환출력 (list, current, last); return; }
void 교환출력 (int list[], int current, int last) { int smallest = current; for (int walker = current + 1; walker <= last; walker++) if (list[walker] < list[smallest]) smallest = walker;