From: Ken Bloom Date: 2008-03-12T01:10:32+09:00 Subject: Re: Ordered Collection On Tue, 11 Mar 2008 07:52:23 -0500, James Gray wrote: > On Mar 11, 2008, at 3:43 AM, Peter Hug wrote: > >> What I really would like is an array that is always ordered. IOW, I >> want >> the object to be inserted at the correct location inside the array when >> the object is added to the array. >> >> Is there an efficient way to do this? > > You could use a priority queue. You can see some pure Ruby code for > this in an old Ruby Quiz: > > http://www.rubyquiz.com/quiz40.html > > James Edward Gray II Binary heap-based priority queues make no (obvious) guarantee about the order of elements, execept that first element in the array is the minimum. More complicated heap structures don't even guarantee that there's an array in there at all. --Ken -- Ken (Chanoch) Bloom. PhD candidate. Linguistic Cognition Laboratory. Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/