'In this quicksort code my last element of list i.e. [44] is not arranged in order

In this quicksort code my last element of list i.e. [44] is not arranged in order

def quicksort(A,l,r):
        if r-l<=1:``
            return()
        yellow = l+1
        for green in range(l+1,r):
            if A[green] <= A[l]:
                A[green],A[yellow]=A[yellow],A[green]
                yellow+=1   
        A[l],A[yellow-1]=A[yellow-1],A[l] 
        quicksort(A,l,yellow-1)
        quicksort(A,yellow,r)  
    #command line
    arr = [22,11,88,66,55,77,33,44]
    quicksort(arr,0,len(arr)-1)
    print(arr)

#output [11,22,33,55,66,77,88,44]



Solution 1:[1]

You're calling quicksort function with one element less than your "arr".

quicksort(arr,0,len(arr)-1)

Last element is being excluded from it. So make it,

quicksort(arr,0,len(arr))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 gajendragarg