Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
just starting out with data structures and algorithms and I need a little need help verifying if my answer is correct.

**Question**:
Assume a priority queue implemented as a sorted list of entries using heap.
Draw the heap after each of the operations: insert(5), insert(7), insert(3), removeMin(),
insert(1), removeMin(), removeMin()
<pre>



What I have tried:

Posts for code project - Album on Imgur[^][^]

My solution is on images 1 and 2 respectively. I cannot figure out how to show the intermediate steps like how 3 is inserted and moves to the top.
Posted
Updated 23-Jun-21 9:49am
Comments
Richard MacCutchan 24-Jun-21 4:52am    
If the queue is sorted, then entries 5 and 7 will need to be moved down before entry 3 can be inserted at the top. This holds true for any new entry. First find its position, which may be between two existing values. Then move all the values which are greater to make space for the new entry. Consider where '6' would need to be placed.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900