Quick sort, I can't solve this bug. Can you help me?

    pivot = a[lb]
    start = lb
    end = ub
    while start < end:
        while a[start] <= pivot:
            start = start + 1
        while a[end] > pivot:
            end = end - 1
        if start < end:
            (a[start], a[end]) = (a[end], a[start])
    (a[lb], a[end]) = (a[end], a[lb])
    return end

def quick_sort(a, lb, ub):
    if lb < ub:
        loc = partition(a, lb, ub)
        quick_sort(a, lb, loc-1)
        quick_sort(a, loc+1, ub)
        

size = int(input("Enter the length of your array = "))
print("Enter the elements of the array by space = ", end="")
a = [int(i) for i in input().split()]
#print(a)

lb = 0
ub = size - 1
quick_sort(a, lb, ub)

print(a)```
![SharedScreenshot|512x235](upload://hFnvkVmHrrAOXhcnpj4F8Dmdux1.jpeg)

You have not posted all the code, partition is missing.

Please post as text not an image - no one can cut-n-paste from an image.
Like you did in the first message but with all the code please.

3 Likes

You haven’t said what the bug is, but what happens if the pivot is the largest value?
Try adding print statement to show what it’s doing.
I also notice that size is unrelated to the length of a. As you’re already asking for the values, I’d suggest inputting them and then having size = len(a).