QuickSort - Partitioning

The Lomuto partition scheme.

Lomuto partition rearranges around pivot: 1.1. Choose last as pivot.

2.2. Index ii tracks boundary of << pivot.

3.3. Scan with jj. If arr[j]<pivotarr[j] < pivot, swap with arr[i+1]arr[i+1], increment ii.

4.4. Swap pivot to i+1i+1.

function partition(arr, low, high):
    pivot = arr[high]
    i = low - 1
    for j from low to high-1:
        if arr[j] < pivot:
            i++; swap(arr[i], arr[j])
    swap(arr[i+1], arr[high])
    return i + 1

Pivot ends at final sorted position.