로딩
요청 처리 중입니다...

[C++언어] 카운팅 정렬 (Counting sort) 알고리즘

 [C++언어] 카운팅 정렬 (Counting sort) 알고리즘

#include using namespace std; int count[100001]; void counting(int *array, int begin, int end) { int temp[100001]; for (int i = begin; i <= end; ++i) { count[array[i]] += 1; } for (int i = 1; i <= 100000; ++i) { count[i] += count[i - 1]; } for (int i = begin; i <= end; ++i) { temp[--count[array[i]]] = array[i]; } for (int i = begin; i <= end; ++i) { array[i] = temp[i - begin]; } } 시간 복잡도: O(n+k), k는 데이터의 최댓값...

# 알고리즘 # 정렬 # 카운팅 # 카운팅정렬