Created
March 29, 2012 21:22
-
-
Save julianbonilla/2243934 to your computer and use it in GitHub Desktop.
Quicksort
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
#! /usr/bin/env python | |
def quicksort(list): | |
# Base case: single element list is sorted. | |
if list == []: | |
return list | |
pivot = list[0] | |
left = quicksort([i for i in list[1:] if i < pivot]) | |
right = quicksort([i for i in list[1:] if i >= pivot]) | |
return left + [pivot] + right |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment