Learn R Programming

rstackdeque (version 1.1.1)

head.rstack: 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

"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).

Value

an rstack.

Details

Runs in $O(n)$ time (in the size of the number of elements requested).

See Also

rstack.

Examples

Run this code
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)

Run the code above in your browser using DataLab