Heap2 Priority Queues Priority Queue 우선순위를 가진 요소에 언제든 접근할 수 있는 구조 PQType(int max) items : 구조체 HeapType 이름. elements : HeapType 멤버 중 데이터 저장하는 배열. template PQType::PQType(int max){ length = 0; items.elements = new ItemType[max]; maxItems = max; } ~PQType() 배열을 삭제해줘야한다! template PQType::~PQType(){ delete []items.elements; } void MakeEmpty() template void PQType::MakeEmpty(){ length = 0; } bool IsEmpty() template bool PQ.. 2023. 6. 9. Heap What is a Heap? local variable은 stack에 있고, dynamic 은 heap에 있다의 heap과 다르다. 맥락을 통해 구분하자. Heap은 binary tree의 한 종류이다. 다음의 두 가지 특징을 만족해야한다. 1. Shape : It must be a complete binary tree 2. Order : 모든 노드는 자기의 children 값보다 커야 한다. (Parent가 가장 커야함) _ Max_Heap 모든 노드를 자기의 children 값보다 작게 하는 Min_Heap도 만들 수 있다. 전체 트리에서 가장 큰 Element = root ReheapDown(int root, int bottom) 가장 큰 노드를 root로 올리고 작은 노드를 down 하려는 목적 .. 2023. 5. 23. 이전 1 다음