digitalmars.D.learn - Sorted sequences
Russel Winder via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
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? =20 --=20 Russel. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder ekiga.n= et 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
May 25 2017
Era Scarecrow <rtcvb32 yahoo.com> writes:
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?
May 25 2017