coding-note icon indicating copy to clipboard operation
coding-note copied to clipboard

problem about selection sort

Open xuewengeophysics opened this issue 6 years ago • 0 comments

陈老师: 您好!感谢您开源如此优秀的项目。 关于选择排序,我觉得在将min_index初始化为待排序数列的第1个元素后,不用再将array[min_index]与array[i]进行比较,因此我认为第二个for循环应该修改为for j in range(i+1, lengths);请问我的理解是否有误呢?请多多指教,谢谢! def SelectionSort(array): lengths = len(array) for i in range(lengths-1): min_index = i for j in range(i+1, lengths): if array[j] < array[min_index]: min_index = j array[i], array[min_index] = array[min_index], array[i]

return array

问雪

xuewengeophysics avatar Feb 17 '19 02:02 xuewengeophysics