View source: R/priority_queue.R
| cpp_priority_queue | R Documentation |
Create a priority queue. Priority queues are hold ordered, non-unique elements.
cpp_priority_queue(x, sorting = c("descending", "ascending"))
x |
An integer, numeric, character, or logical vector. |
sorting |
|
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.
Returns a CppPriorityQueue object referencing a priority_queue in C++.
cpp_queue, cpp_stack.
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.