Deques are a generalization of stacks and queues typically with methods to add, delete and access elements at both sides of the underlying data sequence. As such, the Deque can also be used to mimic both stacks and queues. For the standard S3 interface, see deque().

Details

This class inherits from class Container() and extends it by popleft and peek methods, and reverse and rotate functionality.

See also

Super classes

container::Iterable -> container::Container -> Deque

Methods

Inherited methods


Method addleft()

Add element to left side of the Deque.

Usage

Deque$addleft(value, name = NULL)

Arguments

value

value of ANY type to be added to the Deque.

name

character optional name attribute of the value.

Returns

the Deque object.


Method peek()

Peek at last element of the Deque.

Usage

Deque$peek(default = NULL)

Arguments

default

returned default value if Deque is empty.

Returns

element 'peeked' on the right


Method peekleft()

Peek at first element of the Deque.

Usage

Deque$peekleft(default = NULL)

Arguments

default

returned default value if Deque is empty.

Returns

element 'peeked' on the left


Method popleft()

Delete and return element from the left side of the Deque().

Usage

Deque$popleft()

Returns

element 'popped' from the left side of the Deque()


Method rev()

Reverse all elements of the Deque() in-place.

Usage

Deque$rev()

Returns

the Deque() object.


Method rotate()

Rotate all elements n steps to the right. If n is negative, rotate to the left.

Usage

Deque$rotate(n = 1L)

Arguments

n

integer number of steps to rotate

Returns

returns the Deque() object.


Method clone()

The objects of this class are cloneable with this method.

Usage

Deque$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

d = Deque$new(1, 2, s = "a", v = 1:3)
d$addleft(0)
#> |0, 1, 2, s = "a", v = (1L 2L 3L)|
d$peekleft()
#> [1] 0
d$peek()
#> [1] 1 2 3

d$popleft()
#> [1] 0
d$rev()
#> |v = (1L 2L 3L), s = "a", 2, 1|

d$rotate()
#> |1, v = (1L 2L 3L), s = "a", 2|
d$rotate(2)
#> |"a", 2, 1, v = (1L 2L 3L)|
d$rotate(-3)
#> |v = (1L 2L 3L), "a", 2, 1|