Ruby:简单的插入排序

 #Insertion Sort Method
 def insertionSort(list)
   list.each_with_index do |data,i|
     j = i - 1
     while j >= 0
       break if list[j] <= data
       list[j + 1] = list[j]
       j = j - 1
     end
     list[j + 1] = data
   end
 end

编程技巧