View source: R/priority_queue.R
priority_queue | R Documentation |
priority_queue
creates a priority queue (a.k.a heap).
priority_queue(items = NULL, priorities = rep(0, length(items)))
items |
a list of items |
priorities |
a vector of interger valued priorities |
Following methods are exposed:
.$push(item, priority = 0) .$pop() .$clear() .$size() .$as_list() .$print()
item
: any R object
priority
: a real number, item with larger priority pops first
q <- priority_queue()
q$push("not_urgent")
q$push("urgent", priority = 2)
q$push("not_as_urgent", priority = 1)
q$pop() # urgent
q$pop() # not_as_urgent
q$pop() # not_urgent
q <- priority_queue(list("not_urgent", "urgent"), c(0, 2))
q$push("not_as_urgent", 1)$push("not_urgent2")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.