Queue-class: A Queue reference class

Description Fields Methods Examples

Description

A Queue reference class

Fields

data

Initial data to populate the queue.

Methods

peek(pos = c(1), as.list = FALSE)

Returns (but does not remove) specified positions in queue (or NULL if any one of them is not available). The as.list argument will cause a list to be returned even if only one element requested.

poll()

Removes and returns head of queue (or NULL if queue is empty).

pop(N = 1)

Removes and returns head of queue (or raises error if queue is empty). N is number of items to pop.

push(item)

Inserts element at back of the queue.

size()

Returns the number of items in the queue.

Examples

1
2
3
4
5
6
7
queue <- Queue$new()
queue$push("one")
queue$push(2)
queue$push("three")
queue$size()
queue$pop()
queue$poll()

Example output

[1] 3
[1] "one"
[1] 2

liqueueR documentation built on May 1, 2019, 10:11 p.m.