Skip to content

[BUG] Infinite Loop in Swap Sort Implementation #5249

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

Closed
alxkm opened this issue Jun 23, 2024 · 1 comment · Fixed by #5248
Closed

[BUG] Infinite Loop in Swap Sort Implementation #5249

alxkm opened this issue Jun 23, 2024 · 1 comment · Fixed by #5248
Labels

Comments

@alxkm
Copy link
Contributor

alxkm commented Jun 23, 2024

Description

Description
The current implementation of the Swap Sort algorithm can enter an infinite loop, particularly when dealing with arrays containing duplicate values. This issue was observed in the test case shouldAcceptWhenArrayWithDuplicateValueIsPassed.

Problem
The index variable in the sorting logic is not being updated correctly. As a result, the index may never reach len - 1, causing the algorithm to loop indefinitely.

Solution
Fix the logic to ensure the index variable is updated appropriately.
Add the missing test case to validate the sorting of arrays with duplicate values.
Steps to Reproduce

Steps to reproduce

Run the test case shouldAcceptWhenArrayWithDuplicateValueIsPassed.
Observe that the algorithm enters an infinite loop.
Expected Behavior

Excepted behavior

The algorithm should sort the array correctly and terminate without entering an infinite loop.

Screenshots

No response

Additional context

No response

@alxkm alxkm added the bug label Jun 23, 2024
@alxkm
Copy link
Contributor Author

alxkm commented Jun 23, 2024

A pull request addressing this issue has already been created.

#5248

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant