Description
What would you like to share?
This issue proposes a refactoring to standardize the comparison logic across various sorting algorithms in the sorts
directory.
Currently, some sorting algorithm implementations directly use Comparable.compareTo()
for element comparisons (e.g., array[i].compareTo(array[j]) > 0
), while others utilize the utility methods provided by SortUtils
(e.g., SortUtils.greater(array[i], array[j])
).
The goal of this refactoring is to replace direct compareTo()
calls with the corresponding SortUtils.less()
, SortUtils.greater()
, or SortUtils.greaterOrEqual()
methods where applicable.
Additional information
I have identified the following files that currently use direct compareTo()
calls and can be refactored:
AdaptiveMergeSort.java
BinaryInsertionSort.java
BitonicSort.java
BucketSort.java
(partial, wherecompareTo
is used for boolean comparison)CircleSort.java
DutchNationalFlagSort.java
ExchangeSort.java
FlashSort.java
(partial, wherecompareTo
is used for boolean comparison)IntrospectiveSort.java
OddEvenSort.java
SelectionSort.java
SelectionSortRecursive.java
StalinSort.java
StrandSort.java
WiggleSort.java
(partial, wherecompareTo
is used for boolean comparison)
(Note: Files like CycleSort.java
, PatienceSort.java
, SpreadSort.java
that use compareTo()
for equality checks or value calculations will not be modified, as SortUtils
does not provide direct equivalents for these specific use cases.)
I am willing to create a Pull Request to implement this refactoring.