insert_top.rstack: Insert an element onto the top of an rstack

Description Usage Arguments Details Value References See Also Examples

View source: R/insert_top.rstack.R

Description

Insert an element onto the top of an rstack.

Usage

1
2
## S3 method for class 'rstack'
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

1
2
3
4
5
6
7
8
s <- rstack()
s <- insert_top(s, "a")
s <- insert_top(s, "b")
print(s)

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

rstackdeque documentation built on May 2, 2019, 4:15 a.m.