Last active
October 25, 2017 03:42
-
-
Save sasaki-shigeo/8cd5e59a70673cd19c9aa9538ab7ef31 to your computer and use it in GitHub Desktop.
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
| data = [2, 9, 4, 8, 5, 6, 1] | |
| def selection_sort(data, comp): | |
| for k in range(1, len(data)): | |
| for i in range(0, k): | |
| if comp(data[i], data[k]) > 0: | |
| temp = data[i] | |
| data[i] = data[k] | |
| data[k] = temp | |
| def compare(x, y): | |
| return x - y | |
| selection_sort(data, compare) # ascendant order | |
| print data | |
| selection_sort(data, lambda x, y: y - x) # descendant order | |
| print data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment