Learn R Programming

cppcontainers (version 1.0.4)

cpp_list: Create list

Description

Create a list, i.e. a doubly-linked list.

Usage

cpp_list(x)

Value

Returns a CppList object referencing a list in C++.

Arguments

x

An integer, numeric, character, or logical vector.

Details

Doubly-linked means that list elements store a reference both to the previous element and to the following element. This container type, thus, requires more RAM than a singly-linked list does, but can be iterated in both directions.

C++ list methods implemented in this package are assign, back, clear, emplace, emplace_back, emplace_front, empty, erase, front, insert, max_size, merge, pop_back, pop_front, push_back, push_front, remove., resize, reverse, size, sort, splice, and unique. 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.

See Also

cpp_vector, cpp_deque, cpp_forward_list.

Examples

Run this code
l <- cpp_list(4:6)
l
# 4 5 6

push_back(l, 1L)
l
# 4 5 6 1

push_front(l, 2L)
l
# 2 4 5 6 1

Run the code above in your browser using DataLab