Learn R Programming

container (version 1.0.0)

Deque: Deque Class

Description

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().

Arguments

Super classes

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

Methods

Public 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.

Details

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

See Also

Container(), deque()

Examples

Run this code
# NOT RUN {
d = Deque$new(1, 2, s = "a", v = 1:3)
d$addleft(0)
d$peekleft()
d$peek()

d$popleft()
d$rev()

d$rotate()
d$rotate(2)
d$rotate(-3)
# }

Run the code above in your browser using DataLab