Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
priority queue for Ruby(Kodama's tips page)
[go: Go Back, main page]

Kodama's home / tips.

priority queue for Ruby.

Download: pqueue.rb.

A priority(or ordered,sorted) queue class " PQueue" for Ruby.

Sample script

require "pqueue"

pq=PQueue.new(proc{|x,y| x>y})
pq.push(2)
pq.push(3)
pq.push(4)
pq.push(3)
pq.push(2)
pq.push(4)
print "size:"+pq.size.to_s+"\n"
print "each_pop: "
pq.each_pop{|x| print x.to_s+" "}
print "\n"

Result

size:6
each_pop: 4 4 3 3 2 2 

See also:

Ruby and Ruby Application Archives.
Kodama's home / tips.