Untitled

mail@pastecode.io avatar
unknown
plain_text
8 months ago
596 B
2
Indexable
Never
def quick_sort(arr, low, high):
    if low < high:
        pivot = arr[high]
        i = low - 1
        for j in range(low, high):
            if arr[j] <= pivot:
                i += 1
                arr[i], arr[j] = arr[j], arr[i]
        arr[i+1], arr[high] = arr[high], arr[i+1]
        quick_sort(arr, low, i)
        quick_sort(arr, i+2, high)
    return arr

arr = [15, 5, 28, 10, 7, 20, 12]
print(quick_sort(arr, 0, len(arr)-1))


Apakah di kode ini terdapat partition, coba jelaskan secara detail
Leave a Comment