Last active
August 29, 2015 14:19
-
-
Save dragstar328/4c696e8c15bb3c4aa74c to your computer and use it in GitHub Desktop.
アルゴリズムクイックリファレンス:クイックソート
This file contains 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 quick_sort(target): | |
if len(target) <= 1: | |
return target | |
pivot = target[0] | |
left = [] | |
right = [] | |
for x in xrange(1, len(target)): | |
if target[x] <= pivot: | |
left.append(target[x]) | |
else: | |
right.append(target[x]) | |
left = quick_sort(left) | |
right = quick_sort(right) | |
mid = [pivot] | |
return left + mid + right |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment