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)
|
* [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)
|
* [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)
|
* [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)
|
* [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)
|
* [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)
|
* [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 {
|
public class StoogeSort implements SortAlgorithm {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T extends Comparable<T>> T[] sort(T[] unsortedArray) {
|
public <T extends Comparable<T>> T[] sort(T[] array) {
|
||||||
sort(unsortedArray, 0, unsortedArray.length);
|
if (array.length == 0) {
|
||||||
return unsortedArray;
|
return array;
|
||||||
|
}
|
||||||
|
sort(array, 0, array.length);
|
||||||
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends Comparable<T>> T[] sort(T[] unsortedArray, int start, int end) {
|
public <T extends Comparable<T>> T[] sort(T[] unsortedArray, int start, int end) {
|
||||||
@ -28,24 +31,4 @@ public class StoogeSort implements SortAlgorithm {
|
|||||||
}
|
}
|
||||||
return unsortedArray;
|
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