Coding Test - cpp/Sort
[백준 2750: 수 정렬하기] - C++
에드윈H
2021. 2. 16. 09:05
#include<iostream>
using namespace std;
int n;
void SelectSort(int *arr)
{
int curIndex = 0;
for (int i = 0; i < n; i++)
{
curIndex = i;
for (int j = i + 1; j < n; j++)
{
if (arr[curIndex] > arr[j])
{
curIndex = j;
}
}
int temp = arr[curIndex];
arr[curIndex] = arr[i];
arr[i] = temp;
}
}
int main() {
cin >> n;
int* arr = new int[n];
for (int i = 0; i < n; i++)
{
cin >> arr[i];
}
SelectSort(arr);
for (int i = 0; i < n; i++)
{
cout << arr[i]<< endl;
}
delete arr;
return 0;
}