Difference between revisions of "ObjectType:stack"
Jump to navigation
Jump to search
Line 5: | Line 5: | ||
== Members == | == Members == | ||
− | *sub-type ''' | + | *sub-type '''Top''': Retrieves the first object in the stack |
== Methods == | == Methods == | ||
Line 35: | Line 35: | ||
== Viewing the stack == | == Viewing the stack == | ||
− | To access the first object in the stack (e.g. the first person in line), use the | + | To access the first object in the stack (e.g. the first person in line), use the Top member, as demonstrated in this example |
=== Example 1 === | === Example 1 === | ||
variable stack:int MyStack | variable stack:int MyStack | ||
MyStack:Push[15] | MyStack:Push[15] | ||
MyStack:Push[25] | MyStack:Push[25] | ||
− | echo \${MyStack. | + | echo \${MyStack.Top} should be 25: ${MyStack.Top} |
MyStack:Pop | MyStack:Pop | ||
/* Only 15 is now in the stack */ | /* Only 15 is now in the stack */ | ||
− | echo \${MyStack. | + | echo \${MyStack.Top} should be 15: ${MyStack.Top} |
== See Also == | == See Also == |
Revision as of 23:19, 23 May 2008
Contents
Overview
stack | |
Defined By | LavishScript |
Inherits | objectcontainer |
Reduces To | NULL |
Variable Object Type | stack |
Uses Sub-Types | yes |
C/C++ Type | LSStack * |
A stack is a first-in last-out list of objects.
Members
- sub-type Top: Retrieves the first object in the stack
Methods
- Push[...]: Adds an object to the stack, passing any parameters to the initialization for the given object type
- Pop: Removes the first object in the stack
Declaring stack Variables
stack objects require a sub-type -- an object type to be a stack of. Append the sub-type to the word stack, with a colon separating the words. It is possible to have sub-subtypes (such as stack:stack:int for a stack of stacks of ints).
Example 1
Declaring a stack of "int"
variable stack:int MyStack
Adding items to a stack
To add an item to a stack, use the stack method, as demonstrated in this example
Example 1
variable stack:int MyStack MyStack:Push[15] MyStack:Push[25]
Removing items from a stack
Items are removed in the order stackd -- the first item stackd is the first that will be removed. To remove an item, use the Pop method, as demonstrated in this example
Example 1
variable stack:int MyStack MyStack:Push[15] MyStack:Push[25] MyStack:Pop /* Only 15 is now in the stack */
Viewing the stack
To access the first object in the stack (e.g. the first person in line), use the Top member, as demonstrated in this example
Example 1
variable stack:int MyStack MyStack:Push[15] MyStack:Push[25] echo \${MyStack.Top} should be 25: ${MyStack.Top} MyStack:Pop /* Only 15 is now in the stack */ echo \${MyStack.Top} should be 15: ${MyStack.Top}