Skip to content

Commit 6cdebe2

Browse files
authored
Update StalinSort.java
1 parent 9926906 commit 6cdebe2

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,20 @@ public <T extends Comparable<T>> T[] sort(T[] array) {
1818
}
1919
}
2020

21+
// Create a result array with sorted elements
2122
T[] result = (T[]) java.lang.reflect.Array.newInstance(array.getClass().getComponentType(), currentIndex + 1);
2223
System.arraycopy(array, 0, result, 0, currentIndex + 1);
2324
return result;
2425
}
2526

27+
// Driver Program
2628
public static void main(String[] args) {
29+
// Integer Input
2730
Integer[] integers = {4, 23, 6, 78, 1, 54, 231, 9, 12};
2831
StalinSort stalinSort = new StalinSort();
32+
// print a sorted array
2933
SortUtils.print(stalinSort.sort(integers));
34+
// String Input
3035
String[] strings = {"c", "a", "e", "b", "d"};
3136
SortUtils.print(stalinSort.sort(strings));
3237
}

0 commit comments

Comments
 (0)