Dynamic Arrays as Stack and/or Queue

Just Dave abcdef at 1234.com
Mon Oct 7 17:21:30 UTC 2019


On Monday, 7 October 2019 at 17:18:03 UTC, bachmeier 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.
>
> Does slicing do what you need?
>
> x[1..$]

I have no clue. My problem is I need a stack and queue and I'm a 
little unsure the 'd' way to do it.


More information about the Digitalmars-d-learn mailing list