cpp_priority_queue {cppcontainers} | R Documentation |
Create priority queue
Description
Create a priority queue. Priority queues are hold ordered, non-unique elements.
Usage
cpp_priority_queue(x, sorting = c("descending", "ascending"))
Arguments
x |
An integer, numeric, character, or logical vector. |
sorting |
|
Details
A priority queue is a container, in which the order of the elements depends on their size rather than their time of insertion. As in a stack, elements are removed from the top.
C++ priority queue methods implemented in this package are emplace, empty, pop, push, size, and top. The package also adds various helper functions (print, sorting, 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 CppPriorityQueue object referencing a priority_queue in C++.
See Also
Examples
q <- cpp_priority_queue(4:6)
q
# First element: 6
emplace(q, 10L)
q
# First element: 10
emplace(q, 3L)
q
# First element: 10
top(q)
# [1] 10
q <- cpp_priority_queue(4:6, "ascending")
q
# First element: 4
push(q, 10L)
q
# First element: 4