YouTip LogoYouTip

Python Quicksort

# The main function that implements QuickSort # arr[] --> Array to be sorted, # low --> Starting index, # high --> Ending index def quickSort(arr,low,high): if low<high: # pi is partitioning index, arr is now # at right place pi = partition(arr,low,high) # Separately sort elements before # partition and after partition quickSort(arr, low, pi-1) quickSort(arr, pi+1, high) arr = [10, 7, 8, 9, 1, 5] n = len(arr) quickSort(arr,0,n-1) print ("Sorted array:") for i in range(n): print ("%d" %arr),

Executing the above code outputs the following result:

Sorted array:
1
5
7
8
9
10

Document Object Reference Python3 Examples

← Method OverloadingPython Linear Search β†’