implementing stacks using dynamic arrays

Walter Bright newshound at digitalmars.com
Sun Apr 9 17:32:20 PDT 2006


Mike Capp wrote:
> In article <e1b0dn$28vl$1 at digitaldaemon.com>, Boyko Bantchev says...
>> int[] a;
>> int t;
>> ..
>> a ~= t;
>> which makes a beautiful generic push operation for stacks.
> 
> Maybe beautifully generic, but horrendously inefficient. It gives you linear
> complexity for each push, which is really not what you're looking for in a Stack
> implementation.

No, it is rather efficient. It does't realloc/copy for each push, as it 
uses a power of 2 algorithm to resize the array.



More information about the Digitalmars-d mailing list