Skip to content

fix: avoid infinite loop in SwapSort #5248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 24, 2024
Merged

fix: avoid infinite loop in SwapSort #5248

merged 2 commits into from
Jun 24, 2024

Conversation

alxkm
Copy link
Contributor

@alxkm alxkm commented Jun 23, 2024

There was an issue where this sorting implementation could enter an infinite loop, such as in the test shouldAcceptWhenArrayWithDuplicateValueIsPassed.

The index variable was not being updated correctly.
The index may never reach len - 1 due to the flawed logic, leading to a potential infinite loop.

This fix addresses the issue and adds the missing test for this sorting algorithm.

Fixes #5249.

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • All filenames are in PascalCase.
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
  • All new code is formatted with clang-format -i --style=file path/to/your/file.java

@codecov-commenter
Copy link

codecov-commenter commented Jun 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 39.82%. Comparing base (308bdcf) to head (06770a2).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #5248      +/-   ##
============================================
+ Coverage     39.69%   39.82%   +0.13%     
- Complexity     2430     2437       +7     
============================================
  Files           517      517              
  Lines         15492    15476      -16     
  Branches       2958     2958              
============================================
+ Hits           6149     6164      +15     
+ Misses         9053     9022      -31     
  Partials        290      290              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@alxkm alxkm changed the title Fix Swap Sort Implementation: Correct Logic and Improve Efficiency Issue 5249. Fix Swap Sort Implementation: Correct Logic and Improve Efficiency Jun 23, 2024
@alxkm alxkm requested a review from vil02 June 23, 2024 21:56
@vil02 vil02 changed the title Issue 5249. Fix Swap Sort Implementation: Correct Logic and Improve Efficiency fix: avoid infinite loop in SwapSort Jun 24, 2024
@vil02 vil02 merged commit a5b4c61 into TheAlgorithms:master Jun 24, 2024
5 checks passed
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.

[BUG] Infinite Loop in Swap Sort Implementation
3 participants