Priority Queue

    힙 정렬(heap sort) <priority queue> C++

    min heap 구현 heap[i]의 값은 heap[i * 2] 와 heap[i*2 + 1]의 사이에 있다 BST(이진 탐색 트리)구조를 기반으로 한다 STL의 priority queue를 사용하면 되므로 직접 구현할 일은 없겠지만 heap 자료구조를 직접 구현해 본다는 점에서 의미있다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 #include #include using namespace std; vector heap; void push_heap(vector& heap, int newvalue){ heap.push_back(newvalue); int idx = he..