힙정렬(Heap Sort).
//힙정렬은 힙 트리 구조를 이용하는 정렬방법. //시간복잡도 O(N*logN). #include using namespace std; int number = 9; int heap[9] = { 7, 6, 5, 8, 3, 5, 9, 1, 6 }; int main() { //힙 생성 알고리즘(Heapify) for (int i = 1; i < number; i++) { int c = i; do { int root = (c - 1) / 2; if (heap[root] < heap[c]) { int temp = heap[root]; heap[root] = heap[c]; heap[c] = temp; } c = root; } while (c != 0); } //크기 줄여가며 반복적으로 힙 구성 for (int i..
Algorithm/Basic_Algorithm
2020. 2. 8. 02:32