Learn R Programming

rstackdeque (version 1.1.1)

insert_front: Insert an element into the front of an rdeque

Description

Returns a version of the deque with the new element in the front position.

Usage

insert_front(d, e, ...)

Arguments

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

Value

modified version of the rdeque.

Details

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

References

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

See Also

without_front for removing the front element.

Examples

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

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

Run the code above in your browser using DataLab