[자료구조] 백준 1927번: 최소 힙
#define _CRT_SECURE_NO_WARNINGS #include int heap[100001]; int t = 0; int n; void swap(int i, int j) { int tmp = heap[i]; heap[i] = heap[j]; heap[j] = tmp; } //값 저장 void push(int x) { heap[++t] = x; for (int i = t; i > 1; i /= 2) { if (heap[i] < heap[i / 2]) swap(i, i / 2); else break; } } //내림차순으로 값 출력 int pop() { int top = heap[1]; heap[1] = heap[t]; heap[t--] = 0; int i = 1; while (i * 2 heap..
자료구조
2022. 7. 4. 09:23