Computer Science/Algorithm
[정렬#2] 선택 정렬(Selection Sort)
89점
2015. 10. 11. 00:36
최소값(또는 최대값)을 찾아서 계속해서 앞쪽(또는 뒤쪽)으로 두는 정렬방식...
시간복잡도
123456789101112131415161718192021222324 int main(){int a[10] = { 5, 2, 3, 10, 1, 7, 9, 8, 6, 4 };for (int i = 0; i < 10; i++){int smallestValIndex = i;for (int j = i; j < 10; j++)if (a[j] < a[smallestValIndex]){smallestValIndex = j;int temp = a[i];a[i] = a[smallestValIndex];a[smallestValIndex] = temp;}//print arrayfor (int i = 0; i < 10; i++){cout << a[i] << " ";}cout << endl;return 0;}cs