Learn R Programming

rstackdeque (version 1.1.1)

length.rpqueue: Return the number of elements in an rpqueue

Description

Returns the number of elements in an rpqueue.

Usage

"length"(x)

Arguments

x
rpqueue to get the length of.

Value

a vector of length 1 with the number of elements.

Details

Runs in $O(1)$ time, as this information is stored seperately and updated on every insert/remove.

See Also

empty for checking whether an rpqueue is empty.

Examples

Run this code
q <- rpqueue()
q <- insert_back(q, "a")
print(length(q))         # 1
q <- insert_back(q, "b")
print(length(q))         # 2

Run the code above in your browser using DataLab