Skip to content

Commit 3d7b1b6

Browse files
authored
Update StalinSort.java
1 parent a022b6a commit 3d7b1b6

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,26 @@ public <T extends Comparable<T>> T[] sort(T[] array) {
1616
}
1717
}
1818

19+
// Create a result array with sorted elements
1920
T[] result = (T[]) new Comparable[currentIndex + 1];
2021
System.arraycopy(array, 0, result, 0, currentIndex + 1);
22+
2123
return result;
2224
}
2325

26+
// Driver Program
2427
public static void main(String[] args) {
28+
// Integer Input
2529
Integer[] integers = {4, 23, 6, 78, 1, 54, 231, 9, 12};
30+
2631
StalinSort stalinSort = new StalinSort();
32+
33+
// print a sorted array
2734
SortUtils.print(stalinSort.sort(integers));
28-
35+
36+
// String Input
2937
String[] strings = {"c", "a", "e", "b", "d"};
38+
3039
SortUtils.print(stalinSort.sort(strings));
3140
}
3241
}

0 commit comments

Comments
 (0)