Skip to content

Commit a14dc0d

Browse files
kamleshkrKevinGilmore
authored andcommitted
Updated the previous variable in loop (eugenp#7205)
1 parent 2235c2e commit a14dc0d

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

algorithms-miscellaneous-3/src/main/java/com/baeldung/algorithms/checksortedlist/SortedListChecker.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public static boolean checkIfSortedUsingIterativeApproach(List<String> listOfStr
2727
if (previous.compareTo(current) > 0) {
2828
return false;
2929
}
30+
previous = current;
3031
}
3132
return true;
3233
}
@@ -43,6 +44,7 @@ public static boolean checkIfSortedUsingIterativeApproach(List<Employee> employe
4344
if (employeeComparator.compare(previous, current) > 0) {
4445
return false;
4546
}
47+
previous = current;
4648
}
4749
return true;
4850
}

0 commit comments

Comments
 (0)