I have a SplMaxHeap
with 30 items. Now I want to strip the last 10 ones. How to do this in a decent and efficient way?
The only solutions I see so far is to copy the first 20 items to a new heap or to convert the heap to an array, use the array_slice
and put them also in a new heap.
I even can't see a way to get something out of the heap not from the top.
I guess the reason for this is a limitation of the general design of a heap? I was also thinking to use a DoublyLinkedList
, however there I am missing the automatic sorting.