Skip to content

Instantly share code, notes, and snippets.

@fabianbaechli
Created April 22, 2025 13:56
Show Gist options
  • Select an option

  • Save fabianbaechli/c0f23d970e309fbe6c6a392ec44e6c8b to your computer and use it in GitHub Desktop.

Select an option

Save fabianbaechli/c0f23d970e309fbe6c6a392ec44e6c8b to your computer and use it in GitHub Desktop.
Algo: HoarePartition(A,l,r)
// rightmost element is the pivot element
x = A[r];
i = l-1;
j = r+1;
while true do
// we search for a too small element in the right part
repeat j = j-1 until
A[j]≤x;
// we search for a too large element in the left part
repeat i = i+1 until
A[i]≥x;
// if i and j haven't crossed we exchange
if i<j then
exchange A[i] and A[j]
// else: we return the partitioning point
else
return i;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment