Skip to content

sorts: make reverse_selection_sort generic over Comparable items - #15355

Closed
HarshRajSinghania wants to merge 1 commit into
TheAlgorithms:masterfrom
HarshRajSinghania:sorts/reverse-selection-comparable
Closed

HarshRajSinghania wants to merge 1 commit into
TheAlgorithms:masterfrom
HarshRajSinghania:sorts/reverse-selection-comparable

Conversation

@HarshRajSinghania

Copy link
Copy Markdown
Contributor

Describe your change

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Add or change doctests? -- Note: Please avoid changing both the logic and the tests in a single pull request.
  • Add or change benchmarks?
  • Documentation change?

Checklist

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file plus the shared sort tests.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are type-hinted.
  • All functions have doctests.
  • All new algorithms include at least one URL that points to what they implement.
  • If this pull request resolves one or more issues, I have added the relevant closing keywords.

Notes

Part of #15234

reverse_selection.py is an in-place comparison sort. This PR:

  • adds the Comparable Protocol used by selection_sort.py / insertion_sort.py
  • types reverse_subarray and reverse_selection_sort as MutableSequence[T] with T bound to Comparable
  • adds doctests for strings, mixed int/float, and the mixed-type TypeError failure mode
  • includes reverse_selection_sort in the shared tests/test_sorts.py success and reject batteries

The algorithm body is unchanged.

Testing

python3 -m doctest -v sorts/reverse_selection.py
python3 -m pytest tests/test_sorts.py -q

Doctests: 17 passed.
tests/test_sorts.py: 244 passed.

@algorithms-keeper algorithms-keeper Bot added awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files labels Sep 16, 2026
@cclauss

cclauss commented Sep 16, 2026

Copy link
Copy Markdown
Member

The goal is to spread the workload so multiple visitors can learn how to make these changes.

If one person does them all, others lose the opportunity to learn by doing.

@cclauss cclauss closed this Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants