without_top: Return a version of an rstack without the top element

View source: R/without_top.R

without_topR Documentation

Return a version of an rstack without the top element

Description

Simply returns a version of the given stack without the top element. Results in an error if the structure is empty. The original rstack is left alone.

Usage

without_top(s, ...)

Arguments

s

rstack to remove elements from.

...

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

Details

Runs in O(1) time worst case.

Value

version of the stack with the top n elements removed.

References

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

See Also

insert_top for inserting elements.

Examples

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

s2 <- without_top(s)
print(s2)

print(s)

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