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

Description Usage Arguments Details Value References Examples

View source: R/insert_back.R

Description

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

Usage

1

Arguments

x

rdeque or rpqueue 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 modify the original.

Value

modified version of the rdeque or rpqueue.

References

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

Examples

1
2
3
4
5
6
7
8
d <- rdeque()
d <- insert_back(d, "a")
d <- insert_back(d, "b")
print(d)

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

Example output

A deque with  2  elements.
Front to back: 
 $: chr "a"
 $: chr "b"
A deque with  3  elements.
Front to back: 
 $: chr "a"
 $: chr "b"
 $: chr "c"
A deque with  2  elements.
Front to back: 
 $: chr "a"
 $: chr "b"

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