Stack {rdecision} | R Documentation |
A stack
Description
An R6 class representing a stack of objects of any type.
Details
Conventional implementation of a stack. Used extensively in graph algorithms and offered as a separate class for ease of programming and to ensure that implementations of stacks are optimized. By intention, there is only minimal checking of method arguments. This is to maximize performance and because the class is mainly intended for use internally to rdecision.
Methods
Public methods
Method new()
Create a stack.
Usage
Stack$new()
Returns
A new Stack
object.
Method push()
Push an item onto the stack.
Usage
Stack$push(x)
Arguments
x
The item to push onto the top of the stack. It should be of the same class as items previously pushed on to the stack. It is not checked.
Returns
An updated Stack
object
Method pop()
Pop an item from the stack. Stack underflow and raises an error.
Usage
Stack$pop()
Returns
The item previously at the top of the stack.
Method size()
Gets the number of items on the stack.
Usage
Stack$size()
Returns
Number of items.
Method as_list()
Inspect items in the stack.
Usage
Stack$as_list()
Returns
A list of items.
Method clone()
The objects of this class are cloneable with this method.
Usage
Stack$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.
Author(s)
Andrew Sims andrew.sims@newcastle.ac.uk