File tree Expand file tree Collapse file tree
src/main/java/com/thealgorithms/sorts Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package com .thealgorithms .sorts ;
22
3+ /**
4+ * Implementation of the Selection Sort algorithm.
5+ *
6+ * @see SortAlgorithm
7+ */
38public class SelectionSort implements SortAlgorithm {
49 /**
510 * Generic Selection Sort algorithm.
@@ -11,18 +16,27 @@ public class SelectionSort implements SortAlgorithm {
1116 *
1217 * Space Complexity: O(1) – in-place sorting.
1318 *
14- * @see SortAlgorithm
19+ * @param array the array to be sorted
20+ * @param <T> the type of elements in the array
21+ * @return the sorted array
1522 */
1623 @ Override
1724 public <T extends Comparable <T >> T [] sort (T [] array ) {
18-
1925 for (int i = 0 ; i < array .length - 1 ; i ++) {
2026 final int minIndex = findIndexOfMin (array , i );
2127 SortUtils .swap (array , i , minIndex );
2228 }
2329 return array ;
2430 }
2531
32+ /**
33+ * Finds the index of the minimum element in the array starting from a given index.
34+ *
35+ * @param array the array to search
36+ * @param startIndex the index to start searching from
37+ * @param <T> the type of elements in the array
38+ * @return the index of the minimum element
39+ */
2640 private static <T extends Comparable <T >> int findIndexOfMin (T [] array , final int startIndex ) {
2741 int minIndex = startIndex ;
2842 for (int i = startIndex + 1 ; i < array .length ; i ++) {
You can’t perform that action at this time.
0 commit comments