Skip to content

Commit 873bc00

Browse files
Merge branch 'master' into docs-link-fibonacci-variants
2 parents af1488c + 0d29e7c commit 873bc00

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

src/main/java/com/thealgorithms/sorts/SelectionSort.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package com.thealgorithms.sorts;
22

3+
/**
4+
* Implementation of the Selection Sort algorithm.
5+
*
6+
* @see SortAlgorithm
7+
*/
38
public 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++) {

0 commit comments

Comments
 (0)