MCPcopy Create free account
hub / github.com/geekcomputers/Python / partition

Function partition

Sorting Algorithms/Quick sort.py:1–14  ·  view source on GitHub ↗
(arr, low, high)

Source from the content-addressed store, hash-verified

1def partition(arr, low, high):
2 i = low - 1 # index of smaller element
3 pivot = arr[high] # pivot
4
5 for j in range(low, high):
6 # If current element is smaller than or
7 # equal to pivot
8 if arr[j] <= pivot:
9 # increment index of smaller element
10 i = i + 1
11 arr[i], arr[j] = arr[j], arr[i]
12
13 arr[i + 1], arr[high] = arr[high], arr[i + 1]
14 return i + 1
15
16
17# The main function that implements QuickSort

Callers 1

quickSortFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected