Skip to content

[OTHER] Refactor: Standardize comparison logic using SortUtils #6336

Open
@codingmydna

Description

@codingmydna

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, where compareTo is used for boolean comparison)
  • CircleSort.java
  • DutchNationalFlagSort.java
  • ExchangeSort.java
  • FlashSort.java (partial, where compareTo is used for boolean comparison)
  • IntrospectiveSort.java
  • OddEvenSort.java
  • SelectionSort.java
  • SelectionSortRecursive.java
  • StalinSort.java
  • StrandSort.java
  • WiggleSort.java (partial, where compareTo 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    awaiting triageAwaiting triage from a maintainer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions