Created
March 16, 2013 15:09
-
-
Save joshbode/5176785 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
| def insert_sort(l, inc=1): | |
| """Insert sort.""" | |
| for i, x in enumerate(l): | |
| while x < l[i - inc] and i > 0: | |
| l[i] = l[i - inc] | |
| i -= inc | |
| l[i] = x | |
| def gby_gaps(n): | |
| """Gonnet & Baeza-Yates gaps.""" | |
| inc = n / 2 | |
| while True: | |
| yield inc | |
| inc = 1 if inc == 2 else int(5.0 * inc / 11) | |
| if not inc: | |
| break | |
| def shell_sort(l, steps=gby_gaps): | |
| """Shell sort.""" | |
| for inc in steps(len(l)): | |
| insert_sort(l, inc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment