From: Mathieu Bouchard Date: 2005-03-21T20:40:15+09:00 Subject: Re: Stable sort? On Thu, 17 Mar 2005, Hal Fulton wrote: > 2. Further I believe that such an algorithm could be used to implement > multi-key sorts as "chained" sorts -- correct? > people.sort(:name).sort(:age).sort(:height) no, maybe this: a=people.sort(:name) a.each_extent(:name) {|i,n| a[i,n].sort!(:age) a[i,n] = a[i,n].each_extent(:age) {|i_,n_| # gets worse here... } } where #each_extent is like each_index but also gives the number of elements with the same key and then skip over them: class Array def each_extent(sym) i=j=0 while j