Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
14
Task/Stack/Mathematica/stack.math
Normal file
14
Task/Stack/Mathematica/stack.math
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
EmptyQ[a_] := If[Length[a] == 0, True, False]
|
||||
SetAttributes[Push, HoldAll];[a_, elem_] := AppendTo[a, elem]
|
||||
SetAttributes[Pop, HoldAllComplete];
|
||||
Pop[a_] := If[EmptyQ[a], False, b = Last[a]; Set[a, Most[a]]; b]
|
||||
Peek[a_] := If[EmptyQ[a], False, Last[a]]
|
||||
|
||||
Example use:
|
||||
stack = {};Push[stack, 1]; Push[stack, 2]; Push[stack, 3]; Push[stack, 4];
|
||||
Peek[stack]
|
||||
->4
|
||||
Pop[stack]
|
||||
->4
|
||||
Peek[stack]
|
||||
->3
|
||||
Loading…
Add table
Add a link
Reference in a new issue