<보기>는 히프 정렬(heap sort) 알고리즘을 최대 히… | [7급 서울시 자료구조론] 24년 1회차 기출문제 상세 페이지
1[7급 서울시 자료구조론] 24년 1회차
<보기>는 히프 정렬(heap sort) 알고리즘을 최대 히프(max heap)로 구현한 C언어 코드이다. (가), (나)에 들어갈 코드를 옳게 짝지은 것은? (단, 함수 swap()은 주어진 두 인자의 값을 서로 교환하는 사용자 정의 함수라고 가정한다.)<보기>void adjust(int a[], int root, int n) {
int child, rootkey;
int temp;
temp = a[root];
rootkey = a[root];
child = 2 * root;
while (child <= n) {
if ((child < n) &&
(a[child] < (a[child+1]))
child++;
if ( (가) )
break;
else {
( (나) );
child *= 2;
}
}
a[child/2] = temp;
}
void heapSort(int a[], int n) {
int i;
for (i = n/2; i > 0; i--)
adjust(a, i, n);
for (i = n; i > 1; i--) {
swap(a[1], a[i]);
adjust(a, 1, i-1);
}
}
(가) (나)
1
rootkey < a[child] a[child] = a[child/2]
2
rootkey < a[child] a[child/2] = a[child]
3
rootkey > a[child] a[child] = a[child/2]
4
rootkey > a[child] a[child/2] = a[child]
해설
등록된 해설이 없습니다.
오류나 개정된 내용이 보이면 알려주세요