Dynamic Arrays as Stack and/or Queue
Just Dave
abcdef at 1234.com
Mon Oct 7 17:28:11 UTC 2019
On Monday, 7 October 2019 at 17:24:19 UTC, Ferhat Kurtulmuş wrote:
> On Monday, 7 October 2019 at 17:11:08 UTC, Just Dave wrote:
>> I need a stack and a queue and I noticed that the standard
>> library doesn't appear to have one. Which is ok. I just need
>> something that can logically behave as a stack and queue,
>> which I think the dynamic array should be able to do (if I
>> understand correctly this is effectively the equivalent of
>> vector<T> in C++ or List<T> in C#). However, I'm having a hard
>> time figuring out the best way to push, pop, enqueue and
>> dequeue using D.
>>
>> I'm not seeing here: https://dlang.org/spec/arrays.html,
>> anyway to remove from the array. What's the correct
>> syntax/method call for this? I see you can easily concatenate
>> with '~', but I see no corresponding delete.
>>
>> Sorry for the newbie question, but I'm just unsure where to
>> look for this.
>
> Built-in D arrays rely on garbage collector, and you don't need
> an explicit delete. For nogc arrays, there are 3rd party libs
> and std.container.array. take a look at
> https://dlang.org/phobos/std_container_array.html
I'm not talking about memory deletion. I'm talking about push,
pop, enqueue, and dequeue behavior. I'd assume in a garbage
collected language letting the reference float off should be
picked up by the GC.
More information about the Digitalmars-d-learn
mailing list