insert_top: Insert an element onto the top of an rstack

View source: R/insert_top.R

insert_topR Documentation

Insert an element onto the top of an rstack

Description

Insert an element onto the top of an rstack.

Usage

insert_top(s, e, ...)

Arguments

s

rstack to insert onto.

e

element to insert.

...

additional arguments to be passed to or from methods (ignored).

Details

Runs in O(1) time worst-case. Does not semantically modify the original structure (i.e, this function is "pure").

Value

modified version of the stack with new element at top.

References

Okasaki, Chris. Purely Functional Data Structures. Cambridge University Press, 1999.

See Also

rstack for information on rstacks, without_top for removal of top elements.

Examples

s <- rstack()
s <- insert_top(s, "a")
s <- insert_top(s, "b")
print(s)

s2 <- insert_top(s, "c")
print(s2)
print(s)

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