From 51d9f3e7b4912d89a546905cebffad3ffb931743 Mon Sep 17 00:00:00 2001 From: JulianGStudium Date: Thu, 25 Jun 2026 09:23:07 +0200 Subject: [PATCH 1/2] SelectionSort: add missing Javadoc for class and findIndexOfMin method --- .../thealgorithms/sorts/SelectionSort.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/thealgorithms/sorts/SelectionSort.java b/src/main/java/com/thealgorithms/sorts/SelectionSort.java index 2d1814441701..5f4e6543bca7 100644 --- a/src/main/java/com/thealgorithms/sorts/SelectionSort.java +++ b/src/main/java/com/thealgorithms/sorts/SelectionSort.java @@ -1,5 +1,10 @@ package com.thealgorithms.sorts; +/** + * Implementation of the Selection Sort algorithm. + * + * @see SortAlgorithm + */ public class SelectionSort implements SortAlgorithm { /** * Generic Selection Sort algorithm. @@ -11,11 +16,12 @@ public class SelectionSort implements SortAlgorithm { * * Space Complexity: O(1) – in-place sorting. * - * @see SortAlgorithm + * @param array the array to be sorted + * @param the type of elements in the array + * @return the sorted array */ @Override public > T[] sort(T[] array) { - for (int i = 0; i < array.length - 1; i++) { final int minIndex = findIndexOfMin(array, i); SortUtils.swap(array, i, minIndex); @@ -23,6 +29,14 @@ public > T[] sort(T[] array) { return array; } + /** + * Finds the index of the minimum element in the array starting from a given index. + * + * @param array the array to search + * @param startIndex the index to start searching from + * @param the type of elements in the array + * @return the index of the minimum element + */ private static > int findIndexOfMin(T[] array, final int startIndex) { int minIndex = startIndex; for (int i = startIndex + 1; i < array.length; i++) { @@ -32,4 +46,4 @@ private static > int findIndexOfMin(T[] array, final int } return minIndex; } -} +} \ No newline at end of file From f83087bff91b2dfc2e850ad762d3698e8fdb10fc Mon Sep 17 00:00:00 2001 From: JulianGStudium Date: Thu, 25 Jun 2026 20:10:13 +0200 Subject: [PATCH 2/2] fix: add missing newline at end of file --- src/main/java/com/thealgorithms/sorts/SelectionSort.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/thealgorithms/sorts/SelectionSort.java b/src/main/java/com/thealgorithms/sorts/SelectionSort.java index 5f4e6543bca7..e6d1a16a7af7 100644 --- a/src/main/java/com/thealgorithms/sorts/SelectionSort.java +++ b/src/main/java/com/thealgorithms/sorts/SelectionSort.java @@ -46,4 +46,4 @@ private static > int findIndexOfMin(T[] array, final int } return minIndex; } -} \ No newline at end of file +}