BinaryHeap usage

Matthias Walter xammy at xammy.homelinux.net
Tue Dec 14 20:04:02 PST 2010


Hi all,

suppose I have an array of comparable Foo structs which I want to access
in a sorted order (e.g. a priority queue) using a BinaryHeap object (I
know that for just sorting, the BinHeap is not the right tools), but I
do not want to change the order of the objects in the original array.

I have two ideas on how to do this and just want to know whether they
are the right way:

a) Have an array of Foo*, initialize it from the original and
instantiate the BinaryHeap with a Comparision-predicate that
dereferences first.

b) Have an array of indices that are indicies in the original array
(like a permutation in a permutation group) and access the corresponding
index of the original array for comparison.

Any further ideas for this problem, or did I cover everything already?

Matthias


More information about the Digitalmars-d-learn mailing list