Class Util
java.lang.Object
topics.sorting.utils.Util
Sorting Utilities
A stateless collection of helper methods for array manipulation and element swapping.
- 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.
-
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.
-