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
Summary
Actions Summary Table
Actions | Description |
---|---|
Add(Type value) | This action adds a value at the end of the stack. |
Compare(Libraries.Language.Object object) | This action compares two object hash codes and returns an integer. |
Copy() | This action copies an object and returns the copy. |
Empty() | This action empty's the stack, clearing out all of the items contained within it. |
Equals(Libraries.Language.Object object) | This action determines if two objects are equal based on their hash code values. |
GetHashCode() | This action gets the hash code for an object. |
GetIterator() | This action gets an iterator for the object and returns that iterator. |
GetSize() | This action retrieves the number of elements or nodes in a stack. |
Has(Type value) | This action determines if an addable object contains a certain item. |
IsEmpty() | This action returns a boolean value, true if the container is empty and false if it contains any items. |
Peek() | This action gets the item at the top of the stack(the item will remain in the stack). |
Pop() | This action removes the item at the top of the stack. |
Push(Type value) | This action adds an item to the top of the stack. |
Remove(Type value) | This action removes the first occurrence of an item that is found in the Addable object. |
RemoveAll(Type value) | This action removes all occurrences of an item from the Addable object. |
Actions Documentation
Add(Type value)
This action adds a value at the end of the stack.
Example Code
use Libraries.Containers.Stack
Stack<integer> myStack
myStack:Add(12)
Parameters
- Libraries.Language.Object: The value to be added to the top of the stack.
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.
Example Code
Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)
Parameters
- Libraries.Language.Object: The object to compare to.
Return
integer: The Compare result, Smaller, Equal, or Larger.
Copy()
This action copies an object and returns the copy.
Example Code
use Libraries.Containers.Stack
Stack<integer> myStack
Stack<integer> copyStack
myStack:Add(12)
Object o = myStack:Copy()
copyStack = cast(Stack<integer>, o)
Return
Libraries.Language.Object: Returns a copy of this object.
Empty()
This action empty's the stack, clearing out all of the items contained within it.
Example Code
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.
Example Code
use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)
Parameters
- Libraries.Language.Object: The to be compared.
Return
boolean: True if the hash codes are equal and false if they are not equal.
GetHashCode()
This action gets the hash code for an object.
Example Code
Object o
integer hash = o:GetHashCode()
Return
integer: The integer hash code of the object.
GetIterator()
This action gets an iterator for the object and returns that iterator.
Example Code
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()
Return
Libraries.Containers.Iterator: Returns the iterator for an object.
GetSize()
This action retrieves the number of elements or nodes in a stack.
Example Code
use Libraries.Containers.Stack
Stack<integer> myStack
myStack:Add(12)
integer size = myStack:GetSize()
Return
integer: Returns an integer value representing the size of the stack.
Has(Type value)
This action determines if an addable object contains a certain item.
Example Code
use Libraries.Containers.Stack
Stack<integer> myStack
myStack:Add(12)
myStack:Add(1)
boolean hasItem = myStack:Has(12)
Parameters
- Libraries.Language.Object: The item to find in the Addable object.
Return
boolean: Returns true if the item was in the Addable object and false if it was not.
IsEmpty()
This action returns a boolean value, true if the container is empty and false if it contains any items.
Example Code
use Libraries.Containers.Stack
Stack<integer> myStack
if(myStack:IsEmpty())
output "The stack is empty."
end
Return
boolean: Returns true when the container is empty and false when it is not.
Peek()
This action gets the item at the top of the stack(the item will remain in the stack).
Example Code
use Libraries.Containers.Stack
Stack<integer> myStack
myStack:Push(1)
myStack:Push(2)
integer result = myStack:Pop()
integer topResult = myStack:Peek()
Return
Libraries.Language.Object: The item at the top of the stack.
Pop()
This action removes the item at the top of the stack.
Example Code
use Libraries.Containers.Stack
Stack<integer> myStack
myStack:Push(1)
myStack:Push(2)
integer result = myStack:Pop()
Return
Libraries.Language.Object: The item at the top of the stack.
Push(Type value)
This action adds an item to the top of the stack.
Example Code
use Libraries.Containers.Stack
Stack<integer> myStack
myStack:Push(1)
myStack:Push(2)
Parameters
- Libraries.Language.Object: The item to the top of the stack.
Remove(Type value)
This action removes the first occurrence of an item that is found in the Addable object.
Example Code
use Libraries.Containers.Stack
Stack<integer> myStack
myStack:Add(43)
myStack:Add(13)
myStack:Add(43)
boolean removed = myStack:Remove(43)
Parameters
- Libraries.Language.Object: The item to find in the Addable object.
Return
boolean: Returns true if the item was removed and false if it was not removed.
RemoveAll(Type value)
This action removes all occurrences of an item from the Addable object.
Example Code
use Libraries.Containers.Stack
Stack<integer> myStack
myStack:Add(43)
myStack:Add(13)
myStack:Add(43)
boolean removed = myStack:RemoveAll(43)
Parameters
- Libraries.Language.Object: The item to find in the Addable object.
Return
boolean: Returns true if the item was removed and false if it was not removed.