Create a heap for array with weights

Suppose that I have an array

X = ["a","b","c","d"]

with the corresponding weights

weight = [1,4,3,2]

How can I make heaps of X using weight

using DataStructures
weight_heaps =BinaryMaxHeap(weight)
# What I want to do
X_heaps = BinaryMaxHeap(X,weight=weight)

I can not find it in the DataStructures package documentation. Thank you so much.

So you want a heap with associated data? Perhaps you’re looking for a priority queue:

https://juliacollections.github.io/DataStructures.jl/latest/priority-queue/

1 Like

Thank you so much, this solve my problem.