cpp_stack {cppcontainers} | R Documentation |
Create stack
Description
Create a stack. Stacks are last-in, first-out containers.
Usage
cpp_stack(x)
Arguments
x |
An integer, numeric, character, or logical vector. |
Details
The last element added to a stack is the first one to remove.
C++ stack methods implemented in this package are emplace, empty, pop, push, size, and top. 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
.
Value
Returns a CppStack object referencing a stack in C++.
See Also
cpp_queue, cpp_priority_queue.
Examples
s <- cpp_stack(4:6)
s
# Top element: 6
emplace(s, 3L)
s
# Top element: 3
push(s, 9L)
s
# Top element: 9
pop(s)
s
# Top element: 3
[Package cppcontainers version 1.0.0 Index]