1
- # Python program for implementation of Quicksort Sort
1
+ # Python program for implementation of Quicksort Sort
2
+
3
+ # This function takes last element as pivot, places
4
+ # the pivot element at its correct position in sorted
5
+ # array, and places all smaller (smaller than pivot)
6
+ # to left of pivot and all greater elements to right
7
+ # of pivot
8
+
2
9
3
- # This function takes last element as pivot, places
4
- # the pivot element at its correct position in sorted
5
- # array, and places all smaller (smaller than pivot)
6
- # to left of pivot and all greater elements to right
7
- # of pivot
8
10
def partition (arr , low , high ):
9
11
i = (low - 1 ) # index of smaller element
10
12
pivot = arr [high ] # pivot
@@ -22,12 +24,12 @@ def partition(arr, low, high):
22
24
return (i + 1 )
23
25
24
26
25
- # The main function that implements QuickSort
26
- # arr[] --> Array to be sorted,
27
- # low --> Starting index,
28
- # high --> Ending index
27
+ # The main function that implements QuickSort
28
+ # arr[] --> Array to be sorted,
29
+ # low --> Starting index,
30
+ # high --> Ending index
29
31
30
- # Function to do Quick sort
32
+ # Function to do Quick sort
31
33
def quickSort (arr , low , high ):
32
34
if low < high :
33
35
# pi is partitioning index, arr[p] is now
0 commit comments