MathGroup Archive 1999

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

Search the Archive

Re: implementing a stack

  • To: mathgroup at smc.vnet.net
  • Subject: [mg16409] Re: implementing a stack
  • From: Guilherme Roschke <gr at network3.entropy.upenn.edu>
  • Date: Thu, 11 Mar 1999 02:17:08 -0500
  • Organization: University of Pennsylvania
  • References: <7ag29l$agg@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Will Self wrote:
> 
> 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

Use List functions:
First[list] returns the first element of a list
Rest[list] returns the list minus the first element.

have fun.

-- 
Guilherme Roschke
Programmer
Dept. of Anesthesia
University of Pennsylvania Medical School
gr at network3.entropy.upenn.edu


  • Prev by Date: Re: Printing error in MacOS
  • Next by Date: Re: M-EPS to real EPS
  • Previous by thread: Re: estimating parameters for diffeq model
  • Next by thread: Programmed PageBreaks