Dynamic Arrays as Stack and/or Queue

mipri mipri at minimaltype.com
Mon Oct 7 17:17:46 UTC 2019


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.

if the top of the stack is the last element, --stack.length works
as a simple pop.


More information about the Digitalmars-d-learn mailing list