Skip to content

Instantly share code, notes, and snippets.

@juanplopes
Created April 3, 2012 19:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanplopes/2295119 to your computer and use it in GitHub Desktop.
Save juanplopes/2295119 to your computer and use it in GitHub Desktop.
Quick Sort in python
def quicksort(V):
if len(V) <= 1:
return V
pivot = V[0]
equal = [x for x in V if x == pivot]
lesser = [x for x in V if x < pivot]
greater = [x for x in V if x > pivot]
return quicksort(lesser) + equal + quicksort(greater)
@hacktoon
Copy link

hacktoon commented Apr 3, 2012

Confesso que a minha tentativa foi maior que essa :P

@jonatasemidio
Copy link

Eu quase me assustei quando vi a implementação de quicksort em ASP! rsrsrs http://pt.wikipedia.org/wiki/Quicksort

@viniciushana
Copy link

Ficou bem legível, muito bom!

@jonatasemidio
Copy link

Fala Juan!!
Fiquei curioso e resolvi tentar implementar o quicksort em groovy.

Segue o Gist: https://gist.github.com/jonatasemidio/5540420
1: caso utilizando o algoritimo padrão
2: case utilizando alguns recursos da liguagem como grouopBy e compareTo representado pelo <=>

Acho que o código fica quase tão limpo quanto em python rsrs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment