Skip to content

Instantly share code, notes, and snippets.

@cocodrips
Created January 20, 2014 18:25
Show Gist options
  • Save cocodrips/8525936 to your computer and use it in GitHub Desktop.
Save cocodrips/8525936 to your computer and use it in GitHub Desktop.
Pythonでベーシックなクイックソート( ・ω・)ノ
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