Deque {container} | R Documentation |
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()
.
Details
This class inherits from class Container()
and extends it by
popleft
and peek
methods, and reverse and rotate functionality.
Super classes
container::Iterable
-> container::Container
-> Deque
Methods
Public methods
Inherited methods
container::Iterable$iter()
container::Container$add()
container::Container$at()
container::Container$at2()
container::Container$clear()
container::Container$count()
container::Container$delete()
container::Container$delete_at()
container::Container$discard()
container::Container$discard_at()
container::Container$empty()
container::Container$get_compare_fun()
container::Container$has()
container::Container$has_name()
container::Container$initialize()
container::Container$is_empty()
container::Container$length()
container::Container$names()
container::Container$peek_at()
container::Container$peek_at2()
container::Container$pop()
container::Container$print()
container::Container$remove()
container::Container$rename()
container::Container$replace()
container::Container$replace_at()
container::Container$size()
container::Container$type()
container::Container$update()
container::Container$values()
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 theDeque
.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.
See Also
Examples
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)