Created
April 3, 2012 19:53
-
-
Save juanplopes/2295119 to your computer and use it in GitHub Desktop.
Quick Sort in python
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 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) |
Eu quase me assustei quando vi a implementação de quicksort em ASP! rsrsrs http://pt.wikipedia.org/wiki/Quicksort
Ficou bem legível, muito bom!
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
Confesso que a minha tentativa foi maior que essa :P