head.rstack {rstackdeque} | R Documentation |
Return the head (top) of an rstack
Description
Returns the top n
elements of an rstack as an stack, or all of the elements
if length(x) < n
.
Usage
## S3 method for class 'rstack'
head(x, n = 6L, ...)
Arguments
x |
rstack to get the head/top of. |
n |
number of elements to get. |
... |
arguments to be passed to or from other methods (ignored). |
Details
Runs in O(n)
time (in the size of the number of elements requested).
Value
an rstack
.
See Also
Examples
s <- rstack()
s <- insert_top(s, "a")
s <- insert_top(s, "b")
s <- insert_top(s, "c")
st <- head(s, n = 2)
print(st)
print(s)
[Package rstackdeque version 1.1.1 Index]