From: Dark Ambient Date: 2006-06-29T09:36:34+09:00 Subject: Re: Sorting arrays Actually it's from Chris Pine's book, Learning to Program. I thought it was a bit fuzzy in the book, not so much my understanding but the suggestions he makes to accomplish the task. His idea is to have two additional lists, or arrays , one called "already sorted", and the other "unsorted". I'm just being repetetive here to make the point of where his advice is fuzzy. It reads as if you would use the first array (where the strings were put) and test those against themselves to find the smallest one, where the smallest (one that returns true) goes into the sorted, repeat and the ones that return false go into unsorted. Then the next iteration , or final stage is testing the sorted list against the unsorted list. Using "insertion sort" it seemed that things were moved around in just the initial array. Stuart On 6/28/06, Justin Collins wrote: > On 6/28/06, Nuralanur@aol.com wrote: > > You can use the sort method on the entire Array: > > > > sorted=[1, 2, "three"] > > unsorted=[6,5,'four'] > > a = sorted+unsorted > > b = a.sort { |x,y| x.to_s <=> y.to_s} > > =>b is then [1, 2, 5, 6, "four", "three"] (that's because '1' was > > compared > > to 'four' etc.) > > > > Best regards, > > > > Axel > > > > > > > Dark Ambient wrote: > > Apologies, I can't use array.sort. This is to build my own. > > > > This sounds like a homework problem...? > > In either case, your description is a little fuzzy. The way you describe > it doesn't make sense. This usually means you haven't fully grasped the > problem. Before jumping into the programming, write out what you want to > accomplish on paper and make certain you completely understand what you > wish to do, and how you will go about it. > > Then try to solve it programmatically. If you have trouble with that > piece, come back to the list. That's my advice. > > Good luck! > > -Justin > >