From: Walton Hoops Date: 2009-10-03T01:50:32+09:00 Subject: Re: Control of Priority Queue Order? And size limits on queues? On Thu, 01 Oct 2009 23:38:46 -0600, Mason Kelsey wrote: > Thanks for the reply Christopher. > > No, it would still be a priority queue if I could control the order of > MATCHING key values. I still want the unmatched key values to be sorted > automatically in order ascending or descending as I push new entries onto > the queue. Your focusing on the definition of Priority, and ignoring the Queue part A queue is defined as a First-in-First-out (FiFo) data structure. In other words if I add 'B' to the Queue, then 'A', when I read from the Queue I get 'B' then 'A'. A priority queue changes this behavior, in that items with the higher priority go first. Thus assuming 'B1' and 'B2' are considered equal priority, if I add 'B1' to the Queue, then 'B2', when I read the Queue I MUST first get 'B1' then 'B2' or it ceases to be a Queue. A Stack on the other hand in a First-in-Last-out (FiLo) data structure. So if I add 'B1' then 'B2' and read the Stack, I get out 'B2' then 'B1' in that order. Thus, what you are looking for is a Priority Stack, not a Priority Queue. To answer your question, I don't know of a pre-built Priority Stack for Ruby, but that doesn't mean it doesn't exist. Hope this clears things up!