Skip to content

Update tim_sort.py #972

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 30, 2019
Merged

Update tim_sort.py #972

merged 2 commits into from
Jul 30, 2019

Conversation

FrogBattle
Copy link
Contributor

@FrogBattle FrogBattle commented Jul 8, 2019

Update tim_sort.py

The previous algorithm was skipping numbers, according to issue #959, and my own tests.
The version I am applying uses a while loop, which works correctly and is easier to compute, as there is no break statement.
This implementation only builds up increasing runs, without making decreasing ones, which are later inverted.

Update tim_sort.py

The previous algorithm was skipping numbers, according to issue TheAlgorithms#959, and my own tests.
The version I am applying uses a while loop, which works correctly and is easier to compute, as there is no break statement.
@cclauss
Copy link
Member

cclauss commented Jul 10, 2019

How about adding some doctests?

def tim_sort(lst):
    """
    >>> tim_sort("Python")
    ['P', 'h', 'n', 'o', 't', 'y']
    >>> tim_sort((1.1, 1, 0, -1, -1.1))
    [-1.1, -1, 0, 1, 1.1]
    >>> tim_sort(list(reversed(list(range(7)))))
    [0, 1, 2, 3, 4, 5, 6]
    >>> tim_sort([3, 2, 1]) == insertion_sort([3, 2, 1])
    True
    """

Copy link
Member

@poyea poyea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but please consider adding some doctests or comments on how the algorithm works. It would help readers a lot.

@cclauss cclauss merged commit e58a5e6 into TheAlgorithms:master Jul 30, 2019
stokhos pushed a commit to stokhos/Python that referenced this pull request Jan 3, 2021
* Update tim_sort.py


Update tim_sort.py

The previous algorithm was skipping numbers, according to issue TheAlgorithms#959, and my own tests.
The version I am applying uses a while loop, which works correctly and is easier to compute, as there is no break statement.

* Update tim_sort.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants