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()
.
This class inherits from class Container()
and extends it by
popleft
and peek
methods, and reverse and rotate functionality.
container::Iterable
-> container::Container
-> Deque
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()
addleft()
Add element to left side of the Deque
.
peek()
Peek at last element of the Deque
.
peekleft()
Peek at first element of the Deque
.
rev()
Reverse all elements of the Deque()
in-place.
rotate()
Rotate all elements n
steps to the right. If n is
negative, rotate to the left.
clone()
The objects of this class are cloneable with this method.
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|