Title: | Stack Data Type as an 'R6' Class |
---|---|
Description: | An extremely simple stack data type, implemented with 'R6' classes. The size of the stack increases as needed, and the amortized time complexity is O(1). The stack may contain arbitrary objects. |
Authors: | Gábor Csárdi |
Maintainer: | Gábor Csárdi <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.0.1.9000 |
Built: | 2024-12-23 02:58:59 UTC |
Source: | https://github.com/gaborcsardi/rstack |
Methods:
push(elem)
Puts an R object on the top of the stack.
This operation might trigger the allocation of memory, if the
currently allocated memory cannot hold the new element. Still, the
amortized time complexity of the stack is constant.
The stack may contain arbitrary R objects.
pop()
Removes and returns the top element of the stack.
It throws an error if the stack is empty.
peek()
Returns the top element of the stack. (Without
removing it.) It throws an error if the stack is empty.
size()
Returns the number of elements in the stack.
is_empty()
Returns wheather the stack is empty.
S <- stack$new() S$push(1L) S$peek() S$pop() S$size() S$push(NULL) S$push(iris) colnames(S$peek())
S <- stack$new() S$push(1L) S$peek() S$pop() S$size() S$push(NULL) S$push(iris) colnames(S$peek())