This is an animation of the partition algorithm found in CLR's Algorithms book. The algorithm is used both in quicksort and in selection.

PSEUDOCODE FOR PARTITION (taken from CLR)

Goal: Partition section of array A from A[p] to A[r], inclusive.
Initialization:
  Set Pivot to value at A[r]
  Set low numbers boundary i to p-1
  Set high numbers boundary j to p-1

while p<r
  j++
  if A[j] < Pivot
     then swap values in A[++i] and A[j]

swap values in A[++i] and A[r]
return i
 Restart   Next