s-stack returned by SimpleStacke-arbitrary Maple expression (not an expression sequence)bound-positive integer bounding the maximums size of the stack

<Text-field style="Heading 2" layout="Heading 2" bookmark="info">Description</Text-field>The procedure SimpleStack is a stack constructor. It returns a Maple expression that implements a stack object, which is of type Stack.You can test whether a Maple expression e is a Stack object by using type( e, 'Stack' ). An expression is of type Stack if it is an object with the methods empty, top, push, and pop. Specific Stack implementations may support additional methods, but all Stacks support at least these four methods. Stacks built by the constructor SimpleStack are currently represented by modules, so the message passing syntax uses the :- operator.The empty method returns the value true if no items are on the stack, and returns the value false otherwise.To insert an item e (any Maple expression) on the top of a stack, use the push method. The pushed value is returned.Items may be removed from the top of the stack by using the pop method. An error is raised if the stack is empty. This error may be caught using the exception string "empty stack".The item on the top of a non-empty stack may be examined, without changing the contents of the stack, by using the method top. If the stack is non-empty, this method returns the item on the top of the stack (that value which will be returned by the next call to the pop method), and otherwise raises the "empty stack" exception.Stacks constructed by the SimpleStack constructor also support the methods depth, which returns the number of items on the stack, and init, which initializes the stack (and empties it).The standard include file <Stack.mi> defines several inline procedures for invoking the basic Stack operations. The procedures provided are Enqueue, Dequeue, EmptyP, and Front. These procedures are not part of the Maple library, and are provided only as inlined procedures. (Note: The include file NiMtSSQ8LD5HNiI2Iy1JIi5HNiRJKnByb3RlY3RlZEdGKkkoX3N5c2xpYkdGJTYkSSZRdWV1ZUdGJUkjbWlHRiU= also provides an EmptyP inlined procedure, but it is compatible with the one in <Stack.mi>, so both include files may be used in the same Maple source file.The BoundedStack constructor returns a bounded stack; that is, a stack whose maximum depth is bounded by a predetermined positive integer bound specified in the call to the constructor. Bounded stacks export the additional method full, which returns the value true if the stack is full (no more items can be pushed), and the value false otherwise.A stack which records the numbers of pushes, pops and the maximum stack depth achieved can be created using the MeteredStack constructor. It returns a stack that exports the additional method stats, which returns an expression sequence of three non-negative integers. The first is the total number of pushes effected since the stack was initialized. The second is the total number of pops since the most recent initialization. The third integer in the sequence is the maximum stack depth achieved since the last time the init method was called. The init method for a metered stack resets these counters to NiMiIiE=. Metered stacks are intended to be used for performance monitoring; the extra overhead of tracking the stack statistics imposes a noticeable performance penalty. A useful technique is to include code like the following in your Maple source code.$include <Stack.mi>
$ifdef _DEBUG_
macro( Stack = MeteredStack ):
$else
macro( Stack = SimpleStack ):
$endifFor a non-object-oriented stack implementation, see the stack package.
<Text-field style="Heading 2" layout="Heading 2" bookmark="examples">Examples</Text-field>S := SimpleStack():type( S, 'Stack' );S:-push( 1 ); S:-push( 2 ); S:-push( 3 );S:-depth();S:-top();S:-pop();S:-top();while not S:-empty() do
S:-pop()
end do;S:-depth(); # verify emptyS:-top(); # so no object is on top of the stackMathFolks := MeteredStack(): # create an empty stackMathFolks:-push( "Alex" ):
MathFolks:-push( "Allan" ):
MathFolks:-push( "Dave" ):
MathFolks:-push( "David" ):
MathFolks:-push( "Edgardo" ):
MathFolks:-push( "James" ):
MathFolks:-push( "Juergen" ):
MathFolks:-push( "Laurent" ):
MathFolks:-push( "Michael" ):
MathFolks:-push( "Paulina" ):
MathFolks:-push( "Raqeeb" ):
MathFolks:-push( "Stephen" ):
while not MathFolks:-empty() do
MathFolks:-pop()
end do;MathFolks:-stats();B := BoundedStack( 10 ):for i from 1 to 10 do B:-push( i ) end do:
B:-push( one_more );See AlsoheapmodulepriqueueQueuequeuestacktype