Skip to content

Improve readability in LinearSearch by using local variable#7367

Merged
DenizAltunkapan merged 2 commits intoTheAlgorithms:masterfrom
kadambari25:improve-linear-search-readability
Apr 8, 2026
Merged

Improve readability in LinearSearch by using local variable#7367
DenizAltunkapan merged 2 commits intoTheAlgorithms:masterfrom
kadambari25:improve-linear-search-readability

Conversation

@kadambari25
Copy link
Copy Markdown
Contributor

✨ Improve readability in LinearSearch implementation

Description

This PR improves the readability of the LinearSearch implementation by introducing a local variable for the current element inside the loop.

Instead of directly accessing array[i] multiple times, a variable currentElement is used, making the code cleaner and easier to understand.

Changes Made

  • Introduced a local variable currentElement inside the loop
  • Replaced repeated array access with the local variable
  • No change in functionality

Why this is useful

  • Improves readability for beginners
  • Makes code easier to maintain
  • Follows better coding practices

Checklist

  • I have read [CONTRIBUTING.md](https://github.com/TheAlgorithms/Java/blob/master/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 algorithms include a corresponding test class that validates their functionality
  • All new code is formatted with clang-format -i --style=file path/to/your/file.java

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 7, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 79.51%. Comparing base (7eea9a5) to head (f2c9fe8).

Files with missing lines Patch % Lines
.../java/com/thealgorithms/searches/LinearSearch.java 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #7367      +/-   ##
============================================
- Coverage     79.51%   79.51%   -0.01%     
+ Complexity     7144     7143       -1     
============================================
  Files           796      796              
  Lines         23358    23359       +1     
  Branches       4596     4596              
============================================
  Hits          18574    18574              
  Misses         4047     4047              
- Partials        737      738       +1     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kadambari25
Copy link
Copy Markdown
Contributor Author

This change is only for readability and does not affect logic.
Test coverage remains unchanged functionally.

@DenizAltunkapan DenizAltunkapan enabled auto-merge (squash) April 8, 2026 07:07
@DenizAltunkapan DenizAltunkapan merged commit 49f9e1a into TheAlgorithms:master Apr 8, 2026
7 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.

4 participants