LOMUTO_PARTITION(A,left, right)
- pivotElement ← A[left]
- split ← left
- for i ← left + 1 to right do
- if A[i] < pivotElement
- split ← split + 1
- swap(A[split],A[i])
- swap(A[left],A[split])
- return s
QUICK_SELECT(A,left, right,k)
- if k < left or k > right
- return ERROR
- s ← LOMUTO_PARTITION(A,left,right)
- if s = k-1
- return A[s]
- else if s > k
- return QUICK_SELECT(A, left,s-1)
- else
- return QUICK_SELECT(A, s+1,right)