Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1999
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

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


  • Prev by Date: log log plot
  • Next by Date: Pure Functions in rules
  • Previous by thread: log log plot
  • Next by thread: Re: implementing a stack