DEV Community

Discussion on: Algorithm Tutorial: Intro to Heaps and Priority Queue Implementation

Collapse
 
dsasse07 profile image
Daniel Sasse

Hi Artem,

Thank you for reading! In my implementation of a MaxPriority Queue, when a value is inserted, the function accepts the value and the priority value, and stores this data in an object representing each node of the tree.

When the bubble and trickle methods execute, all comparisons are made using the priority property of those nodes, not the values themselves. This ensures that nodes bubble up or trickle down based on their assigned priority levels.

Collapse
 
artemkislov profile image
Artem Kislov

Thank you for reply!
But I still don't see any comparisons using priority. Yeah, you pass priority, but you compare objects, not priority values. I talk about Full code section -> class MaxHeapPriorityQueue. So MaxHeapPriorityQueue class looks the same as MaxHeap (except formatting)

Thread Thread
 
dsasse07 profile image
Daniel Sasse • Edited

Oh! I see what you mean now. It looks like I forgot to update the gist from my local file (which is what I looked at after your previous comment). I updated the gist from my local file, namely lines 28 of _bubble_up() and 73 & 88 of _trickle_down()

Thank you for bringing it to my attention, and persisting!