Created
April 22, 2025 13:56
-
-
Save fabianbaechli/c0f23d970e309fbe6c6a392ec44e6c8b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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