Skip to content

Commit 49f9e1a

Browse files
Improve readability in LinearSearch by using local variable (TheAlgorithms#7367)
Co-authored-by: Kadambari <kadambari179@gmail.com>
1 parent 7eea9a5 commit 49f9e1a

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/main/java/com/thealgorithms/searches/LinearSearch.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ public <T extends Comparable<T>> int find(T[] array, T value) {
5151
}
5252

5353
for (int i = 0; i < array.length; i++) {
54-
if (array[i] != null && array[i].compareTo(value) == 0) {
54+
T currentElement = array[i];
55+
if (currentElement != null && currentElement.compareTo(value) == 0) {
5556
return i;
5657
}
5758
}

0 commit comments

Comments
 (0)