Difference between revisions of "ObjectType:stack"

From Lavish Software Wiki
Jump to navigation Jump to search
 
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 +
{{ObjectType-Vitals|stack|[[LavishScript]]|[[ObjectType:objectcontainer|objectcontainer]]|NULL|stack|yes|LSStack *}}
 
== Overview ==
 
== Overview ==
{{ObjectType-Vitals|stack|[[LavishScript]]|[[ObjectType:objectcontainer|objectcontainer]]|NULL|stack|yes|LSStack *}}
 
  
 
A '''stack''' is a first-in last-out list of objects.
 
A '''stack''' is a first-in last-out list of objects.
  
 
== Members ==
 
== Members ==
*sub-type '''Peek''': Retrieves the first object in the stack
+
*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 Peek member, as demonstrated in this example
+
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.Peek} should be 25: ${MyStack.Peek}
+
  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.Peek} should be 15: ${MyStack.Peek}
+
  echo \${MyStack.Top} should be 15: ${MyStack.Top}
  
 
== See Also ==
 
== See Also ==
* [[LavishScript]]
+
{{LavishScript:ObjectType}}
 
 
[[Category:LavishScript]]
 

Latest revision as of 16:14, 8 July 2018

Object Type Vitals
stack
Defined By LavishScript
Inherits objectcontainer
Reduces To NULL
Variable Object Type stack
Uses Sub-Types yes
C/C++ Type LSStack *

Overview

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}

See Also

LavishScript Object Types