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, element swapping, and educational execution tracing.

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.
    static void
    trace(int iteration, int[] elements)
    Logs the current state of the array during a specific iteration.
    static void
    traceMessage(String message, int[] elements)
    Logs a custom contextual message alongside the array contents.
    static void
    traceShellSort(int k, int pos, int[] elements)
    Logs the specific state for the Shell Sort algorithm.

    Methods inherited from class Object

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

    • trace

      public static void trace(int iteration, int[] elements)
      Logs the current state of the array during a specific iteration.
      Parameters:
      iteration - The current algorithmic loop iteration.
      elements - The array being sorted.
    • traceShellSort

      public static void traceShellSort(int k, int pos, int[] elements)
      Logs the specific state for the Shell Sort algorithm.
      Parameters:
      k - Value of the gap sequence parameter.
      pos - Value of the current position parameter.
      elements - The array being sorted.
    • traceMessage

      public static void traceMessage(String message, int[] elements)
      Logs a custom contextual message alongside the array contents.
      Parameters:
      message - The message to be logged.
      elements - The array being sorted.
    • 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 largest element.