Class Util

java.lang.Object
topics.sorting.utils.Util

public final class Util extends Object

Sorting Utilities

A stateless collection of helper methods for array manipulation and element swapping.

Author:
vicegd
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    findPosMax(int[] elements, int firstElement)
    Locates the position of the largest element within a specific sub-array.
    static int
    findPosMin(int[] elements, int firstElement)
    Locates the position of the smallest element within a specific sub-array.
    static void
    swap(int[] elements, int i, int j)
    Interchanges (swaps) two elements within an array in-place.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • swap

      public static void swap(int[] elements, int i, int j)
      Interchanges (swaps) two elements within an array in-place.
      Parameters:
      elements - The target array.
      i - Position of the first element.
      j - Position of the second element.
    • findPosMin

      public static int findPosMin(int[] elements, int firstElement)
      Locates the position of the smallest element within a specific sub-array.
      Parameters:
      elements - The target array.
      firstElement - The starting index for the search boundary.
      Returns:
      The index of the smallest element.
    • findPosMax

      public static int findPosMax(int[] elements, int firstElement)
      Locates the position of the largest element within a specific sub-array.
      Parameters:
      elements - The target array.
      firstElement - The starting index for the search boundary.
      Returns:
      The index of the smallest element.