partition

corsort.partition(xs, i, j, lt)[source]

Move the pivot element to the right place and return its position (for quicksort or quickselect).

Parameters:
  • xs (ndarray) – Array to sort.

  • i (int) – Index of the left boundary.

  • j (int) – Index of the right boundary.

  • lt (callable) – lt(x, y) is the test used to determine whether element x is lower than y.

Returns:

Pivot index.

Return type:

int

Examples

>>> my_xs = np.array([4, 1, 7, 6, 0, 8, 2, 3, 5])
>>> partition(my_xs, i=0, j=len(my_xs) - 1, lt=lambda x, y: x < y)
4
>>> my_xs
array([1, 0, 2, 3, 4, 7, 6, 8, 5])