Created
November 3, 2018 20:30
-
-
Save righthandabacus/14ffd5bd1c449e57e107b9c9ee7db184 to your computer and use it in GitHub Desktop.
Stalin 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 stalinsort(unsorted): | |
"""Stalin sort: O(n) sort algorithm that iterate down a | |
list of elements, any element which is out of order is | |
eliminated. | |
https://www.facebook.com/ProgrammersCreateLife/photos/a.241809332534619/1934139766634892/?type=1&theater | |
Args: | |
unsorted: Iterable of elements that support >= operator | |
Returns: | |
A list of subset of the input | |
""" | |
output = [] | |
for x in unsorted: | |
if not output or x >= output[-1]: | |
output.append(x) | |
return output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment