From: Mario Camou Date: 2009-09-21T11:31:01+09:00 Subject: Re: Multi-Dimensional Arrays in Priority Queues --001636ed70ae8cf01e04740d4587 Content-Type: text/plain; charset=ISO-8859-1 Hi, In the line: pq.push([2], [123456780], [123456708]) you're not passing in a multi-dimensional array, you're passing 3 parameters each of which is an array. Try with: pq.push([[2], [123456780], [123456708]]) (notice the double [ at the beginning and the double ] at the end). you will also have to change your PQueue creation to something like this: pq=PQueue.new(proc{|x,y| x[0] wrote: > In my program I need to construct a priority queue that sorts ascending. > The basic idea can be expressed in the following simple code that uses a > Priority Queue concept. See: > http://www.math.kobe-u.ac.jp/~kodama/tips-ruby-pqueue.html > > 1 require "pqueue" > 2 > 3 pq=PQueue.new(proc{|x,y| x 4 pq.push(2) > 5 pq.push(3) > 6 pq.push(4) > 7 pq.push(3) > 8 pq.push(2) > 9 pq.push(4) > 10 print "size:"+pq.size.to_s+"\n" > 11 print "each_pop: " > 12 pq.each_pop{|x| print x.to_s+" "} > 13 print "\n" > > This is clean and simple to understand. But I need to be able to put into > the queue several components per push to make an entire record object. I > need to have three components: an integer heuristic value, followed by two > 9 > digit configuration patterns, such as > pq.push([2], [123456780], [123456708]) But this gives me an argument error > message: > pqueue.rb:4:in `push': wrong number of arguments (3 for 1) > (ArgumentError) from pqueue.rb:4 > > or pq.push(2_123456780_123456708) ignores the underscore separators and > runs > the 3 parts together as one long number. > > Still learning Ruby and none of the books address multiple dimensional > arrays very well. Is the Priority Queue not able to handle > multi-dimensional arrays? Can this code be modified to allow > multi-elements > in each push and still sort on the first element? > > If I cannot use pqueue, is there another required library of methods that > will work with three elements in each array entry? > > Thanks in advance to those of you who can help. And thanks to all who help > out on this forum. Very good forum. > > No Sam > --001636ed70ae8cf01e04740d4587--