Skip to content

Instantly share code, notes, and snippets.

@zerohours
Created July 13, 2011 02:41
Show Gist options
  • Save zerohours/1079615 to your computer and use it in GitHub Desktop.
Save zerohours/1079615 to your computer and use it in GitHub Desktop.
Quicksort on Python
def quicksort(datos, primero, ultimo):
i = primero
j = ultimo
pivote = (datos[primero] + datos[ultimo]) / 2
while i < j:
while datos[i] < pivote:
i+=1
while datos[j] > pivote:
j-=1
if i <= j:
aux = datos[i]
datos[i] = datos[j]
datos[j] = aux
i+=1
j-=1
if primero < j:
datos = quicksort(datos, primero, j)
if ultimo > i:
datos = quicksort(datos, i, ultimo)
return datos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment