我的selection_sort代码有什么问题? [处于保留状态]

问题描述 投票:0回答:1
def swap(A, x, y):
    A[x], A[y] = A[y], A[x]
    return A


def selection_sort(A):

    for i in range(len(A)):
        smallest = i
        for j in range(i+1, len(A)):
            if A[smallest] > A[j]:
                smallest = j
        if smallest != i:
            swap(A, i, j)

A = [23, 10, 6, 40, 25]
print(selection_sort(A))
python sorting selection
1个回答
0
投票

您必须在selection_sort函数中最后一条指令“返回A”

© www.soinside.com 2019 - 2024. All rights reserved.