힙정렬(heap sort) 이진 트리 : 모든 노드의 자식 노드가 2개 이하인 트리구조 완전 이진트리 힙정렬 #include void swap(int *a, int *b) { int temp = *a; *a = *b; *b = temp; } void heapify(int arr[], int here, int size) { int left = here * 2 + 1; int right = here * 2 + 2; int max=here; if (left arr[max]) max = left; if (right arr[max]) max = right; if (max != here) { swap(&arr[here], &arr[max]); heapify(arr, max, .. 2021. 1. 13. 이전 1 다음