MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / lomuto_partition

Function lomuto_partition

sorts/quick_sort_3_partition.py:75–88  ·  view source on GitHub ↗

Example: >>> lomuto_partition([1,5,7,6], 0, 3) 2

(sorting: list, left: int, right: int)

Source from the content-addressed store, hash-verified

73
74
75def lomuto_partition(sorting: list, left: int, right: int) -> int:
76 """
77 Example:
78 >>> lomuto_partition([1,5,7,6], 0, 3)
79 2
80 """
81 pivot = sorting[right]
82 store_index = left
83 for i in range(left, right):
84 if sorting[i] < pivot:
85 sorting[store_index], sorting[i] = sorting[i], sorting[store_index]
86 store_index += 1
87 sorting[right], sorting[store_index] = sorting[store_index], sorting[right]
88 return store_index
89
90
91def three_way_radix_quicksort(sorting: list) -> list:

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected