sorts: make recursive_insertion_sort generic over Comparable items - #15340
Open
Rokesh2008 wants to merge 1 commit into
Open
Rokesh2008 wants to merge 1 commit into
Rokesh2008 wants to merge 1 commit into
Conversation
Part of TheAlgorithms#15234 - switch rec_insertion_sort/insert_next to the Comparable/TypeVar-bound MutableSequence[T] pattern (in-place sorts bucket) per the convention discussed on TheAlgorithms#15234 - make rec_insertion_sort return the sorted collection and give n a default of len(collection), so it can be called with a single argument like the other sorts in the shared test battery - add a string doctest - register rec_insertion_sort in tests/test_sorts.py's shared SORTS battery and the non-comparable-items rejection test
Member
|
ON HOLD: Our focus is on merging or closing old pull requests before October 1st. |
44 tasks
Member
|
ON HOLD: Our focus is on merging or closing old pull requests before October 1st. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #15234
This is an in-place sort, so it follows the
MutableSequence[T]bucket of theComparable/TypeVarconvention discussed on #15234, rather than theIterable[T] -> list[T]bucket used by copy-and-return sorts:rec_insertion_sort/insert_nextnow takeMutableSequence[T]bound toComparablerec_insertion_sortnow returns the sorted collection (previously-> None) andndefaults tolen(collection), so it can be called with a single argument — needed so it fits the sharedSORTSbattery intests/test_sorts.py, which calls every sort assort(list(case))rec_insertion_sortin the sharedSORTSbattery (checked againstsorted(), including thePerson/Dogcomparable objects) and intest_sort_rejects_non_comparable_itemsTests:
python -m doctest -v sorts/recursive_insertion_sort.py— 18/18 passedrec_insertion_sortagainst every case intests/test_sorts.py'sCASEStuple with a single-argument call, matchingsorted()rec_insertion_sort([1, "a"])raisesTypeErrorLinking with
Part of #15234rather than a closing keyword, per the issue's contribution guidance.