Learn R Programming

rstackdeque (version 1.1.1)

insert_back: Insert an element into the back of an rdeque or rpqueue

Description

Returns a version of the deque/queue with the new element in the back position.

Usage

insert_back(x, e, ...)

Arguments

x
rdeque or rpqueue to insert onto.
e
element to insert.
...
additional arguments to be passed to or from methods (ignored).

Value

modified version of the rdeque or rpqueue.

Details

Runs in $O(1)$ time worst-case. Does not modify the original.

References

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

Examples

Run this code
d <- rdeque()
d <- insert_back(d, "a")
d <- insert_back(d, "b")
print(d)

d2 <- insert_back(d, "c")
print(d2)
print(d)

Run the code above in your browser using DataLab