head.rstack: Return the head (top) of an rstack

View source: R/head.rstack.R

head.rstackR 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

rstack.

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)

oneilsh/rstackdeque documentation built on May 17, 2022, 6:29 p.m.