Repository navigation
Conversation
This branch has not been deployed
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.
Describe your change
data_structures/linked_list/merge_sort_linked_list.py::mergecompared whole nodes withleft <= right.Nodeis a@dataclass(order=True), so that compares(data, next)tuples. When the two heads hold equal values, Python goes on to compare theirnextfields, and as soon as one of them isNoneit raisesTypeError: '<=' not supported between instances of 'Node' and 'NoneType'. Somerge_sort_linked_listcrashes on most lists with repeated values, for example1 -> 1 -> 1or2 -> 1 -> 2 -> 1 -> 2. Where it did not crash it was also walking the rest of both lists to break ties.mergenow comparesleft.data <= right.data, which is what the function means and keeps the sort stable.I added a doctest with repeated values (
2 -> 1 -> 2 -> 1 -> 2); it fails onmasterwith theTypeError, and I kept it in this PR as the regression evidence for this one-line fix. Over 400 random lists of up to 9 values drawn from 0..6 the sorted result equalssorted(values)after the change (three seeds); onmaster, 111 of the 400 lists raised with seed 1 and 135 with seed 2 (I did not run seed 3 onmaster).ruff check,ruff format --checkandpython -m doctestpass.Written with the help of Claude Code (Claude Sonnet 5.5).
Checklist