Skip to content

Improve readability in LinearSearch by using local variable#7367

Open
kadambari25 wants to merge 1 commit intoTheAlgorithms:masterfrom
kadambari25:improve-linear-search-readability
Open

Improve readability in LinearSearch by using local variable#7367
kadambari25 wants to merge 1 commit 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 Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 79.51%. Comparing base (13aaad2) to head (5da90c9).
⚠️ Report is 2 commits behind head on master.

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.46%   79.51%   +0.05%     
- Complexity     7131     7142      +11     
============================================
  Files           795      796       +1     
  Lines         23297    23359      +62     
  Branches       4587     4596       +9     
============================================
+ Hits          18513    18575      +62     
+ Misses         4047     4046       -1     
- 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.

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.

3 participants