def minindex array_,index_ index=nil beginindex = 0 minvalue = array_[0] if index_ > 0 beginindex=index_+1 minvalue = array_[index_] end for j in beginindex...array_.size if array_[j] < minvalue minvalue =array_[j] index=j end end return indexendfor j in 0...array.size-1 oldmin=minindex array,j if oldmin!=nil key=array[j] array[j]=array[oldmin] array[oldmin]=key endend