diff --git a/DIRECTORY.md b/DIRECTORY.md index ef7d163a..0c14970b 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -891,6 +891,7 @@ * [SortingAlgorithmTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/SortingAlgorithmTest.java) * [SortUtilsRandomGeneratorTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/SortUtilsRandomGeneratorTest.java) * [SortUtilsTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/SortUtilsTest.java) + * [StoogeSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/StoogeSortTest.java) * [StrandSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/StrandSortTest.java) * [SwapSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/SwapSortTest.java) * [TimSortTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/sorts/TimSortTest.java) diff --git a/src/main/java/com/thealgorithms/sorts/StoogeSort.java b/src/main/java/com/thealgorithms/sorts/StoogeSort.java index 330f9752..25830109 100644 --- a/src/main/java/com/thealgorithms/sorts/StoogeSort.java +++ b/src/main/java/com/thealgorithms/sorts/StoogeSort.java @@ -7,9 +7,12 @@ package com.thealgorithms.sorts; public class StoogeSort implements SortAlgorithm { @Override - public > T[] sort(T[] unsortedArray) { - sort(unsortedArray, 0, unsortedArray.length); - return unsortedArray; + public > T[] sort(T[] array) { + if (array.length == 0) { + return array; + } + sort(array, 0, array.length); + return array; } public > T[] sort(T[] unsortedArray, int start, int end) { @@ -28,24 +31,4 @@ public class StoogeSort implements SortAlgorithm { } return unsortedArray; } - - public static void main(String[] args) { - StoogeSort stoogeSort = new StoogeSort(); - - Integer[] integerArray = {8, 84, 53, 953, 64, 2, 202}; - // Print integerArray unsorted - SortUtils.print(integerArray); - - stoogeSort.sort(integerArray); - // Print integerArray sorted - SortUtils.print(integerArray); - - String[] stringArray = {"g", "d", "a", "b", "f", "c", "e"}; - // Print stringArray unsorted - SortUtils.print(stringArray); - - stoogeSort.sort(stringArray); - // Print stringArray sorted - SortUtils.print(stringArray); - } } diff --git a/src/test/java/com/thealgorithms/sorts/StoogeSortTest.java b/src/test/java/com/thealgorithms/sorts/StoogeSortTest.java new file mode 100644 index 00000000..e230ac2a --- /dev/null +++ b/src/test/java/com/thealgorithms/sorts/StoogeSortTest.java @@ -0,0 +1,12 @@ +package com.thealgorithms.sorts; + +public class StoogeSortTest extends SortingAlgorithmTest { + protected int getGeneratedArraySize() { + return 1000; + } + + @Override + SortAlgorithm getSortAlgorithm() { + return new StoogeSort(); + } +}