Skip to content

Conversation

@amirsoroush
Copy link
Contributor

Describe your change:

Fixes #9002.

  • type hints added.
  • I left the return value untouched as other sorting algorithms are all returning the mutated list.

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • 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 annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

Copy link
Contributor

@tianyizheng02 tianyizheng02 left a comment

Choose a reason for hiding this comment

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

LGTM

Regarding the function simultaneously modifying the list and returning it, I definitely don't like that behavior either. Perhaps instead we could simply have an optional bool parameter in_place that determines whether the function modifies the input list or returns a new sorted list. I've seen this idea used by pandas functions and I think it could work well here.

@tianyizheng02 tianyizheng02 merged commit b3dc6ef into TheAlgorithms:master Aug 21, 2023
@amirsoroush amirsoroush deleted the patch_insertion_sort branch August 22, 2023 10:23
@isidroas isidroas mentioned this pull request Jan 25, 2025
14 tasks
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.

improvement to insertion_sort algorithm

2 participants