Skip to content

Commit a5210f6

Browse files
renamed method variables for improved readibility in the sort method of InsertionSort
1 parent d867288 commit a5210f6

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/main/java/com/thealgorithms/sorts/InsertionSort.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,30 +33,30 @@ public <T extends Comparable<T>> T[] sort(T[] array) {
3333
}
3434

3535
/**
36-
* Sorts a subarray of the given array using the standard Insertion Sort algorithm.
36+
* Sorts a subarray of the given items using the standard Insertion Sort algorithm.
3737
*
38-
* @param array The array to be sorted
39-
* @param lo The starting index of the subarray
40-
* @param hi The ending index of the subarray (exclusive)
41-
* @param <T> The type of elements in the array, which must be comparable
42-
* @return The sorted array
38+
* @param items The items to be sorted
39+
* @param startIndex The starting index of the subarray
40+
* @param endIndex The ending index of the subarray (exclusive)
41+
* @param <T> The type of elements in the items, which must be comparable
42+
* @return The sorted items
4343
*/
44-
public <T extends Comparable<T>> T[] sort(T[] array, final int lo, final int hi) {
45-
if (array == null || lo >= hi) {
46-
return array;
44+
public <T extends Comparable<T>> T[] sort(T[] items, final int startIndex, final int endIndex) {
45+
if (items == null || startIndex >= endIndex) {
46+
return items;
4747
}
4848

49-
for (int i = lo + 1; i < hi; i++) {
50-
final T key = array[i];
49+
for (int i = startIndex + 1; i < endIndex; i++) {
50+
final T key = items[i];
5151
int j = i - 1;
52-
while (j >= lo && SortUtils.less(key, array[j])) {
53-
array[j + 1] = array[j];
52+
while (j >= startIndex && SortUtils.less(key, items[j])) {
53+
items[j + 1] = items[j];
5454
j--;
5555
}
56-
array[j + 1] = key;
56+
items[j + 1] = key;
5757
}
5858

59-
return array;
59+
return items;
6060
}
6161

6262
/**

0 commit comments

Comments
 (0)