Learn R Programming

rstackdeque (version 1.1.1)

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

Description

Returns the number of elements in an rstack.

Usage

"length"(x)

Arguments

x
rstack to get the length of.

Value

a vector of length 1, which the number of elements of the stack.

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 rstack is empty.

Examples

Run this code
s <- rstack()
s <- insert_top(s, "a")
print(length(s))         # 1
s <- insert_top(s, "b")
print(length(s))         # 2

Run the code above in your browser using DataLab