Created
January 20, 2014 18:25
-
-
Save cocodrips/8525936 to your computer and use it in GitHub Desktop.
Pythonでベーシックなクイックソート( ・ω・)ノ
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 quickSort(data, left, right): | |
index = partition(data, left, right) | |
if left < index - 1: | |
quickSort(data, left, index - 1) | |
if index < right: | |
quickSort(data, index, right) | |
def partition(data, left, right): | |
pivot = data[(left + right) / 2] | |
while left < right: | |
while data[left] < pivot: | |
left += 1 | |
while data[right] > pivot: | |
right -= 1 | |
if left < right and data[left] > data[right]: | |
tmp = data[left] | |
data[left] = data[right] | |
data[right] = tmp | |
left += 1 | |
right -= 1 | |
return left |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment