Learn R Programming

cppcontainers (version 1.0.4)

cpp_queue: Create queue

Description

Create a queue. Queues are first-in, first-out containers.

Usage

cpp_queue(x)

Value

Returns a CppQueue object referencing a queue in C++.

Arguments

x

An integer, numeric, character, or logical vector.

Details

The first element added to a queue is the first one to remove.

C++ queue methods implemented in this package are back, emplace, empty, front, pop, push, and size. The package also adds the == operator and various helper functions (print, to_r, type).

All object-creating methods in this package begin with cpp_ to avoid clashes with functions from other packages, such as utils::stack and base::vector.

Examples

Run this code
q <- cpp_queue(1:4)
q
# First element: 1

push(q, 9L)
q
# First element: 1
back(q)
# [1] 9

emplace(q, 10L)
back(q)
# [1] 10

Run the code above in your browser using DataLab