Sorted sequences
Era Scarecrow via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu May 25 06:08:32 PDT 2017
On Thursday, 25 May 2017 at 10:39:01 UTC, Russel Winder wrote:
> C++ has std:priority_queue as a wrapper around a heap to create
> a sorted queue. Am I right in thinking that D has no direct
> equivalent, that you have to build you own wrapper around a
> heap?
Do you even need a wrapper?
Glancing at priority_queue it more or less ensures the largest
element is always first...
However glancing at the D documentation, you already get the
same thing.
https://dlang.org/phobos/std_container_binaryheap.html
@property ElementType!Store front();
Returns a copy of the front of the heap, which is the
largest element according to less.
A quick test shows inserted items are both sorted and you get
the largest element immediately. So honestly it sounds like it's
already built in... no modification or wrapper needed, unless of
course I'm missing something?
More information about the Digitalmars-d-learn
mailing list