Skip to content

sorts: make odd_even_sort support comparable items - #15307

Closed
deerred643-star wants to merge 2 commits into
TheAlgorithms:masterfrom
deerred643-star:fix-odd-even-sort-comparable
Closed

deerred643-star wants to merge 2 commits into
TheAlgorithms:masterfrom
deerred643-star:fix-odd-even-sort-comparable

Conversation

@deerred643-star

Copy link
Copy Markdown
Contributor

Part of #15234

Summary

  • make odd_even_sort generic over comparable item types ([T: Comparable])
  • rewrite the two > comparisons as < so the algorithm only relies on __lt__, which is what the Comparable protocol guarantees
  • add non-integer doctest coverage (str, float) and a TypeError doctest for mixed non-comparable items
  • add odd_even_sort to test_sort_rejects_non_comparable_items
  • fix the docstring :param: name, which did not match the actual argument

The algorithm itself is unchanged: same odd/even phase loop, same swap logic, same complexity.

Tests

  • python -m doctest -v sorts/odd_even_sort.py
  • python -m pytest tests/test_sorts.py
  • ruff check sorts/odd_even_sort.py tests/test_sorts.py

- make odd_even_sort generic over comparable item types
- rewrite the two > comparisons as < so the algorithm only relies on __lt__,
  which is what the Comparable protocol guarantees
- add non-integer doctest coverage (str, float) and a TypeError doctest
  for mixed non-comparable items
- add odd_even_sort to test_sort_rejects_non_comparable_items
- fix the docstring :param: name, which did not match the actual argument

Ref TheAlgorithms#15234
@cclauss

cclauss commented Sep 12, 2026

Copy link
Copy Markdown
Member

Please only fix one sort so we can have good first issues for others on October 1st.

@cclauss cclauss closed this Sep 12, 2026
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.

2 participants