Skip to content

Commit 44c2856

Browse files
authored
Update AdaptiveMergeSort.java
1 parent 0a550c1 commit 44c2856

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,29 @@ private <T extends Comparable<T>> void merge(T[] array, T[] aux, int low, int mi
2727
aux[k] = array[k];
2828
}
2929

30-
int i = low, j = mid + 1;
30+
int i = low;
31+
int j = mid + 1;
3132
for (int k = low; k <= high; k++) {
32-
if (i > mid)
33+
if (i > mid) {
3334
array[k] = aux[j++];
34-
else if (j > high)
35+
} else if (j > high) {
3536
array[k] = aux[i++];
36-
else if (aux[j].compareTo(aux[i]) < 0)
37+
} else if (aux[j].compareTo(aux[i]) < 0) {
3738
array[k] = aux[j++];
38-
else
39+
} else {
3940
array[k] = aux[i++];
41+
}
4042
}
4143
}
4244

4345
public static void main(String[] args) {
4446
AdaptiveMergeSort adaptiveMergeSort = new AdaptiveMergeSort();
47+
48+
// Integer Input
4549
Integer[] integers = {4, 23, 6, 78, 1, 54, 231, 9, 12};
4650
SortUtils.print(adaptiveMergeSort.sort(integers));
4751

52+
// String Input
4853
String[] strings = {"c", "a", "e", "b", "d"};
4954
SortUtils.print(adaptiveMergeSort.sort(strings));
5055
}

0 commit comments

Comments
 (0)