TheAlgorithms / Java

All Algorithms implemented in Java
MIT License
60.2k stars 19.47k forks source link

Fix loops issues #6086

Open Treizzer opened 2 weeks ago

Treizzer commented 2 weeks ago

Modified while and for loop to fix the infinite loop and negative indices issues, respectively. What happened before the fix: Whether you have and array of numbers like -> Integer[] numbers = { 3, 12, 14, 23, 34, 45, 56, 67, 78, 89 }; When you send a value to "Key" greater than the last number in your array, e.g. 90 or greater, the program got into infinite loop and never return the expected "-1" for "key not found". In case what the for-loop assignment a negative number to the variable "i" the condition will skip the negative index, and the for-loop will continue with the normal flow.

codecov-commenter commented 2 weeks ago

Codecov Report

Attention: Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 73.51%. Comparing base (e63ba4b) to head (3f4ba78).

Files with missing lines Patch % Lines
...in/java/com/thealgorithms/searches/JumpSearch.java 60.00% 1 Missing and 1 partial :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #6086 +/- ## ============================================ + Coverage 73.50% 73.51% +0.01% - Complexity 5097 5099 +2 ============================================ Files 657 657 Lines 17625 17628 +3 Branches 3393 3394 +1 ============================================ + Hits 12955 12960 +5 Misses 4166 4166 + Partials 504 502 -2 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.