Priority Queues
Announcements
Today:
First, speculate on what type of data you can put into it!
YES
NO
ADT: ________________
insert
remove
getSize
Tell me everything you can about this structure:
Describe its implementation…
void heap<T>::insert(const T & key) { if (size == capacity) growArray(); size++; items[size] = key; heapifyUp(size); }
growArray()
void heap<T>::heapifyUp(int cIndex) { if (cIndex > _____) if (items[cIndex] ___ items[parent(cIndex)]) { swap(__________, __________); heapifyUp(__________); } }
T heap<T>::removeMin() { T minVal = items[1]; items[1] = items[size]; size--; heapifyDown(1); return minVal; }
void heap<T>::heapifyDown(int cIndex) { if (hasAChild(cIndex)) { minChildIndex = minChild(cIndex); if (items[cIndex] ___ items[minChildIndex]) { swap(__________, __________); ___________________________ } } }