Skip to content

Instantly share code, notes, and snippets.

@gnrfan
Created September 20, 2014 18:58
Show Gist options
  • Save gnrfan/ec17211ff35ec4e3d2c7 to your computer and use it in GitHub Desktop.
Save gnrfan/ec17211ff35ec4e3d2c7 to your computer and use it in GitHub Desktop.
Quicksort en Python
def quicksort(array, debug=False):
if array:
left = quicksort([x for x in array[1:] if x < array[0]])
right = quicksort([x for x in array[1:] if x >= array[0]])
if debug:
print "left", left
print "right", right
print "array[:1]", array[:1]
return left + array[:1] + right
return []
if __name__ == '__main__':
array = [10, 3, 18, 1, 29, 4, 17, 28, 14]
print quicksort(array)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment