Skip to content

Commit bff1ecb

Browse files
authored
Update StalinSort.java
1 parent be7d4ff commit bff1ecb

File tree

1 file changed

+0
-14
lines changed

1 file changed

+0
-14
lines changed

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,16 @@ public <T extends Comparable<T>> T[] sort(T[] array) {
66
if (array.length == 0) {
77
return array;
88
}
9-
109
int currentIndex = 0;
1110
for (int i = 1; i < array.length; i++) {
1211
if (array[i].compareTo(array[currentIndex]) >= 0) {
1312
currentIndex++;
1413
array[currentIndex] = array[i];
1514
}
1615
}
17-
1816
// Create a result array with sorted elements
1917
T[] result = (T[]) java.lang.reflect.Array.newInstance(array.getClass().getComponentType(), currentIndex + 1);
2018
System.arraycopy(array, 0, result, 0, currentIndex + 1);
2119
return result;
2220
}
23-
24-
// Driver Program
25-
public static void main(String[] args) {
26-
// Integer Input
27-
Integer[] integers = {4, 23, 6, 78, 1, 54, 231, 9, 12};
28-
StalinSort stalinSort = new StalinSort();
29-
// print a sorted array
30-
SortUtils.print(stalinSort.sort(integers));
31-
// String Input
32-
String[] strings = {"c", "a", "e", "b", "d"};
33-
SortUtils.print(stalinSort.sort(strings));
34-
}
3521
}

0 commit comments

Comments
 (0)