-
-
Save reterVision/1620e7d82517fe0d9f9d to your computer and use it in GitHub Desktop.
Quick 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
| """ | |
| Quick Sort | |
| """ | |
| def quick_sort(array): | |
| if len(array) <= 1: | |
| return array | |
| pivot = array[0] | |
| array = array[1:] | |
| left, right = [], [] | |
| for item in array: | |
| if item <= pivot: | |
| left.append(item) | |
| else: | |
| right.append(item) | |
| return quick_sort(left) + [pivot] + quick_sort(right) | |
| if __name__ == "__main__": | |
| array = [7, 5, 4, 1, 2, 3, 9, 8, 10] | |
| print quick_sort(array) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment