Skip to content

problem about selection sort #1

@xuewengeophysics

Description

@xuewengeophysics

陈老师:
您好!感谢您开源如此优秀的项目。
关于选择排序,我觉得在将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

问雪

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions