The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Inactive » comp.soft-sys.math.mathematica

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Making a stack.
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  

Posts: 60
Registered: 9/24/11
Making a stack.
Posted: Oct 22, 2012 2:07 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hi, I'm trying to make stack functions like enqueue and dequeue to
demonstrate algorithms. I know enqueue would do pretty much the same thing
as AppendTo, but I want the arguments reversed and it to be called
"enqueue". I figured this would work:

enqueue[x_, queue_] := AppendTo[queue, x];

But it spits out red. I tried to tinker with the evaluation order but to no
avail. Is anyway to make this work? I want the functions to work like they
would in a procedural language (I'm not using a procedural language because
I want to accompany the algorithms with visualizations---i.e. it's for a
demonstration project). I know I can just use Set when I want to que
something, but I was hoping to figure out a way to make the code look like
procedural code, and I'm guessing Mathematica is flexible enough to do

Any ideas?

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.