Last active
August 29, 2015 13:57
-
-
Save rohitdholakia/9884021 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
def three_way(a, lo, hi): | |
''' dutch national flag problem for 3-way partitioning in quicksort''' | |
key = a[random.randint(lo, hi)] | |
less, equal = lo | |
greater = hi | |
while equal < high: | |
if a[less] < key: | |
a[less], a[equal] = a[equal], a[less] | |
less += 1 | |
equal += 1 | |
elif a[less] == key: | |
equal += 1 | |
else: | |
greater -= 1 | |
a[greater], a[equal] = a[equal], a[greater] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment