Class Util
java.lang.Object
topics.sorting.utils.Util
Sorting Utilities
A stateless collection of helper methods for array manipulation, element swapping, and educational execution tracing.
- Author:
- vicegd
-
Method Summary
Modifier and TypeMethodDescriptionstatic intfindPosMax(int[] elements, int firstElement) Locates the position of the largest element within a specific sub-array.static intfindPosMin(int[] elements, int firstElement) Locates the position of the smallest element within a specific sub-array.static voidswap(int[] elements, int i, int j) Interchanges (swaps) two elements within an array in-place.static voidtrace(int iteration, int[] elements) Logs the current state of the array during a specific iteration.static voidtraceMessage(String message, int[] elements) Logs a custom contextual message alongside the array contents.static voidtraceShellSort(int k, int pos, int[] elements) Logs the specific state for the Shell Sort algorithm.
-
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
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.
-