Data Structure - Heap
阿新 • • 發佈:2018-11-19
Min Heap or Max Heap
這篇文章以Min Heap為例
特徵:parent<children, 所以root永遠是最小的元素
Insertion:goes to the next empty spot and then bubble it up
Remove the min: 1. remove the min
2.replace with last node and then bubble down
Array Implementation
Parent index = (index-1)/2;
left child index = index*2+1;
right child index = index*2+2;
Priority Queue C++
empty();
size();
top();
push();
pop();
emplace();
swap();
Reference: