implementing a stack
- To: mathgroup at smc.vnet.net
- Subject: [mg15922] implementing a stack
- From: wself at viking.emcmt.edu (Will Self)
- Date: Wed, 17 Feb 1999 23:33:56 -0500
- Sender: owner-wri-mathgroup at wolfram.com
I would like to implement a simple stack in Mathematica. I can use PrependTo for "push", but in that case how do I implement "pop"? I have thought about this and I see that I can do it by creating a global variable that keeps a list of pairs: the symbols that serve as the names of the stacks, and the stacks themselves; and having pop and push access and manipulate this list. Is that really what I have to do? Explicitly, push[a, 1] should push the number 1 onto the stack a, and return nothing, and pop[a] should return whatever is on the top of stack a, and reset a to be the rest of the stack. Will Self
- Follow-Ups:
- Re: implementing a stack
- From: Daniel Lichtblau <danl>
- Re: implementing a stack