Hello, today i got stuck on creating 2 functions that could find a max and extract the max from a priority queue. I have done pretty much everything except these 2 examples. If anyone could offer any advice or help id love that.
If this is supposed to be a true priority queue (maintaining heap property) then your insert function is wrong. Once you understand how to insert properly then you will understand how to extract max. Seek and you will find
Otherwise the most straightforward way of doing this is to
- search through the array and find the position of the max element
- replace it by the last element in the array
- decrement the size of the array