0
点赞
收藏
分享

微信扫一扫

快速排序法

JamFF 2022-03-26 阅读 154
python

目前正在学习快速排序法,但是不知道为什么我这个程序在第二个while处无法跳出,先记录问题

A = [1,7,5,3,8,9,2,10]
def swap(a,b):
    temp = A[a]
    A[a] = A[b]
    A[b] = temp

def change():
    temp = A[2]
    swap(0,2)
    i = 0
    j = len(A)-1
    while i!=j:
        while A[i]<=temp and i<=j:
            i = i + 1
            print(i)
        swap(i,j)
        while A[j]>temp and i<=j:
            j = j - 1
        swap(i,j)
    A[i] = temp
    print(A)
change()

举报

相关推荐

0 条评论