class Sort
$array=[41,58,31,41,59,26]
def insertSort(count,key)
if count>=1
insertSort(count-1,$array[count-1])
i=count-1
while i>=0 and $array[i]>key
$array[i+1]=$array[i]
i=i-1
end
$array[i+1]=key
end
end
def Output
puts $array
end
end
sort=Sort.new()
sort.insertSort($array.length-1,$array[$array.length-1])
sort.Output
插入排序 递归 ruby
最新推荐文章于 2021-09-10 19:52:16 发布