insert_top.rstack {rstackdeque} | R Documentation |
Insert an element onto the top of an rstack.
## S3 method for class 'rstack'
insert_top(s, e, ...)
s |
rstack to insert onto. |
e |
element to insert. |
... |
additional arguments to be passed to or from methods (ignored). |
Runs in O(1)
time worst-case. Does not semantically modify the original structure (i.e, this
function is "pure").
modified version of the stack with new element at top.
Okasaki, Chris. Purely Functional Data Structures. Cambridge University Press, 1999.
rstack
for information on rstacks, without_top
for removal of top elements.
s <- rstack()
s <- insert_top(s, "a")
s <- insert_top(s, "b")
print(s)
s2 <- insert_top(s, "c")
print(s2)
print(s)