면접 준비

선택 정렬(Selection Sort) 구현

꾸준함. 2019. 10. 6. 04:54


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int MAX = 1e6;
vector<int> v(MAX, 0);
void selectionSort(void)
{
for (int i = 0; i < v.size() - 1; i++)
{
int temp = v[i];
// 최솟값 탐색
for (int j = i + 1; j < v.size(); j++)
{
if (v[j] < v[temp])
{
temp = j;
}
}
if (i != temp)
{
swap(v[i], v[temp]);
}
}
}
view raw .cpp hosted with ❤ by GitHub

반응형