From: Mike Agres Date: 2006-10-15T13:51:26+09:00 Subject: Re: Learn to Program, by Chris Pine He Fa: Good Job! However, I don't fully understand how this worked. > words_array.each do |word| > if word.to_s.downcase > sorted_array.last.to_s.downcase > #add word to the end of sorted_array > sorted_array.push word > > else > index = (sorted_array.length) - 1 > initial_number = index > temp_array = [] The second WHILE section was where I got really confused. > #check word against next word in sorted_array and repeat > while word.to_s.downcase < sorted_array[index].to_s.downcase > #add the sorted_array to a temp_array up to that point > temp_array[index] = sorted_array[index] > #erase words in sorted_array up to that point > sorted_array.pop > index = index - 1 > end > > #add the word to sorted_array > sorted_array.push word > > #add one by one the words from temp_array to sorted_array > while index < initial_number > sorted_array.push temp_array[index + 1] > index = index + 1 > end > end > end > > puts sorted_array I've been wrapping my head around my own version of the non-recursive sort for days and haven't made it work. -- Posted via http://www.ruby-forum.com/.