AtCoder::PriorityQueue(T)
Inherits Enumerable / Reference / Object
Implements standard priority queue like std::priority_queue.
q = AtCoder::PriorityQueue(Int64).new
q << 1_i64
q << 3_i64
q << 2_i64
q.pop # => 3
q.pop # => 2
q.pop # => 1
Constructors
new
Sourcenew(enumerable : Enumerable(T), &block : T, T -> Bool)
Initializes queue with the elements in enumerable and the custom comperator.
If the second argument b should be popped earlier than
the first argument a, return true. Else, return false.
q = AtCoder::PriorityQueue.new([1, 3, 2]) { |a, b| a >= b }
q.pop # => 1
q.pop # => 2
q.pop # => 3
new
Initializes queue with the custom comperator.
If the second argument b should be popped earlier than
the first argument a, return true. Else, return false.
q = AtCoder::PriorityQueue(Int64).new { |a, b| a >= b }
q << 1_i64
q << 3_i64
q << 2_i64
q.pop # => 1
q.pop # => 2
q.pop # => 3
Class methods
max(enumerable : Enumerable(T))
Create a new queue in ascending order of priority with the elements in enumerable.
min(enumerable : Enumerable(T))
Create a new queue in descending order of priority with the elements in enumerable.
Instance methods
heap
Sourcepush(v : T) : self
Pushes value into the queue. This method returns self, so several calls can be chained.