refactor: cleanup StoogeSort
(#5283)
* refactor: cleanup StoogeSort * refactor: update DIRECTORY.md for StoogeSortTest --------- Co-authored-by: Alex Klymenko <alx@alx.com>
This commit is contained in:
parent
94032148ca
commit
97d416e64e
@ -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)
|
||||
|
@ -7,9 +7,12 @@ package com.thealgorithms.sorts;
|
||||
public class StoogeSort implements SortAlgorithm {
|
||||
|
||||
@Override
|
||||
public <T extends Comparable<T>> T[] sort(T[] unsortedArray) {
|
||||
sort(unsortedArray, 0, unsortedArray.length);
|
||||
return unsortedArray;
|
||||
public <T extends Comparable<T>> T[] sort(T[] array) {
|
||||
if (array.length == 0) {
|
||||
return array;
|
||||
}
|
||||
sort(array, 0, array.length);
|
||||
return array;
|
||||
}
|
||||
|
||||
public <T extends Comparable<T>> 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);
|
||||
}
|
||||
}
|
||||
|
12
src/test/java/com/thealgorithms/sorts/StoogeSortTest.java
Normal file
12
src/test/java/com/thealgorithms/sorts/StoogeSortTest.java
Normal file
@ -0,0 +1,12 @@
|
||||
package com.thealgorithms.sorts;
|
||||
|
||||
public class StoogeSortTest extends SortingAlgorithmTest {
|
||||
protected int getGeneratedArraySize() {
|
||||
return 1000;
|
||||
}
|
||||
|
||||
@Override
|
||||
SortAlgorithm getSortAlgorithm() {
|
||||
return new StoogeSort();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user