From: Dark Ambient Date: 2006-07-09T22:22:35+09:00 Subject: Re: Sorting arrays ------=_Part_128507_9949591.1152451351565 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 7/8/06, Matthew Smillie wrote: > > So, starting off with an empty sorted array, recursive_sort finds the > > *lowest* element (not the first element) in the unsorted array, adds > > it to the sorted array, and removes it from the unsorted array. I'm trying to take this in one step at a time. Only I can't grasp, the mechanics of the first step. In theory I follow what's supposed to be going on but that's not helping my understanding. I re-created the first step slightly and dropped the recursion. def sort(list) sorted = [] unsorted = [] lowest = nil list.each do |item| if lowest == nil || item < lowest lowest = item end end sorted.push(lowest) puts sorted end mylist = ['five', 'three', 'one', 'ten', 'eight'] sort mylist Amazingly :), 'eight' is pushed into the first element of the sorted array. When I asked some posts back through about the elements being compared to nil I was told that wasn't the case. However, lowest is being set to nil. Then the statement lowest is equal to nil, or item smaller then lowest (or nil). I believe nil has a value, which is 0 or false. However how can any item be smaller then it. Bottom line is I'm not seeing the magic here in the comparison to find the correct element. My apologies for my density with this code. Stuart ------=_Part_128507_9949591.1152451351565--