Libraries.Containers.Stack Documentation

The Stack class is a data structure that stores items as if you were "stacking" them. It adds items to the top of the Stack, and when an item is requested to be removed, the top item is pulled from the Stack (Last In First Out). The Stack class is similar to the List class.

Example Code

use Libraries.Containers.Stack
class Main
action Main
   //make the queue
   Stack<integer> myStack
   //add a value
   myStack:Push(12)
   myStack:Push(13)
   myStack:Push(14)
   //remove the top item (14)
   integer value = myStack:Pop()
end
end

Inherits from: Libraries.Language.Object

Actions Documentation

Add(Type value)

This action adds a value at the end of the stack.

Parameters

Example

use Libraries.Containers.Stack
Stack<integer> myStack
myStack:Add(12)

Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.

Parameters

Return

integer: The Compare result, Smaller, Equal, or Larger.

Example

Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)

Copy()

This action copies an object and returns the copy.

Return

Libraries.Language.Object: Returns a copy of this object.

Example

use Libraries.Containers.Stack
Stack<integer> myStack
Stack<integer> copyStack
myStack:Add(12)
Object o = myStack:Copy()
copyStack = cast(Stack<integer>, o)

Empty()

This action empty's the stack, clearing out all of the items contained within it.

Example

use Libraries.Containers.Stack
Stack<integer> myStack
myStack:Add(12)
myStack:Empty() //the item we added is now gone

Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

Parameters

Return

boolean: True if the hash codes are equal and false if they are not equal.

Example

use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)

GetHashCode()

This action gets the hash code for an object.

Return

integer: The integer hash code of the object.

Example

Object o
integer hash = o:GetHashCode()

GetIterator()

This action gets an iterator for the object and returns that iterator.

Return

Libraries.Containers.Iterator: Returns the iterator for an object.

Example

use Libraries.Containers.Stack
use Libraries.Containers.Iterator
Stack<integer> myStack
myStack:Add(12)
myStack:Add(13)
myStack:Add(12)
Iterator<integer> StackIterator = myStack:GetIterator()

GetSize()

This action retrieves the number of elements or nodes in a stack.

Return

integer: Returns an integer value representing the size of the stack.

Example

use Libraries.Containers.Stack
Stack<integer> myStack
myStack:Add(12)
integer size = myStack:GetSize()

Has(Type value)

This action determines if an addable object contains a certain item.

Parameters

Return

boolean: Returns true if the item was in the Addable object and false if it was not.

Example

use Libraries.Containers.Stack
Stack<integer> myStack
myStack:Add(12)
myStack:Add(1)
boolean hasItem = myStack:Has(12)

IsEmpty()

This action returns a boolean value, true if the container is empty and false if it contains any items.

Return

boolean: Returns true when the container is empty and false when it is not.

Example

use Libraries.Containers.Stack
Stack<integer> myStack
if(myStack:IsEmpty())
    output "The stack is empty."
end

Peek()

This action gets the item at the top of the stack(the item will remain in the stack).

Return

Libraries.Language.Object: The item at the top of the stack.

Example

use Libraries.Containers.Stack
Stack<integer> myStack
myStack:Push(1)
myStack:Push(2)
integer result = myStack:Pop()
integer topResult = myStack:Peek()

Pop()

This action removes the item at the top of the stack.

Return

Libraries.Language.Object: The item at the top of the stack.

Example

use Libraries.Containers.Stack
Stack<integer> myStack
myStack:Push(1)
myStack:Push(2)
integer result = myStack:Pop()

Push(Type value)

This action adds an item to the top of the stack.

Parameters

Example

use Libraries.Containers.Stack
Stack<integer> myStack
myStack:Push(1)
myStack:Push(2)

Remove(Type value)

This action removes the first occurrence of an item that is found in the Addable object.

Parameters

Return

boolean: Returns true if the item was removed and false if it was not removed.

Example

use Libraries.Containers.Stack
Stack<integer> myStack
myStack:Add(43)
myStack:Add(13)
myStack:Add(43)
boolean removed = myStack:Remove(43)

RemoveAll(Type value)

This action removes all occurrences of an item from the Addable object.

Parameters

Return

boolean: Returns true if the item was removed and false if it was not removed.

Example

use Libraries.Containers.Stack
Stack<integer> myStack
myStack:Add(43)
myStack:Add(13)
myStack:Add(43)
boolean removed = myStack:RemoveAll(43)