python - My quicksort code is not working. What's wrong with it? -
def quicksort(a): if len(a) > 1: pivot = a[0] = 1 j = len(a)-1 while j >= i: if a[i] < a[0]: += 1 elif a[j] > a[0]: j = j-1 elif a[i] > a[0] , a[j] < a[0]: a[i],a[j] = a[j],a[i] += 1 j = j-1 a[0],a[j] = a[j],a[0] quicksort(a[:j]) quicksort(a[j+1:]) = [9,4,1,3,2,5,8,6,7] quicksort(a) print
in result,all getting list returned first , last values swapped.
Comments
Post a Comment