Created
August 6, 2015 16:41
-
-
Save saxbophone/acf4a9ef9061dab85500 to your computer and use it in GitHub Desktop.
Python Recursive Sort
This file contains hidden or 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 sort(unsorted, asc=True): | |
| if len(unsorted) == 1: | |
| return [unsorted[0]] | |
| else: | |
| smallest = 0 | |
| for i in range(len(unsorted)): | |
| if unsorted[i] > smallest: | |
| smallest = unsorted[i] | |
| unsorted.remove(smallest) | |
| if asc: | |
| return sort(unsorted) + [smallest] | |
| else: | |
| return [smallest] + sort(unsorted, asc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment