Skip to content

Commit bb33ccb

Browse files
committed
💡 Add javadoc
1 parent ff4e07c commit bb33ccb

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Sorting/SelectionSort.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
1+
/**
2+
* Utility class for sorting an array using Selection Sort algorithm. Selection
3+
* Sort is a basic algorithm for sorting with O(n^2) time complexity. Basic idea
4+
* of this algorithm is to find a local minimum, which is the minimum value from
5+
* (i+1) to length of the array [i+1, arr.length), and swap it with the current
6+
* working index (i).
7+
*
8+
* @author Kongpon Charanwattanakit
9+
*
10+
*/
111
public class SelectionSort {
212

13+
/**
14+
* Sort an array using Selection Sort algorithm.
15+
*
16+
* @param arr
17+
* is an array to be sorted
18+
*/
319
public static void sort(int[] arr) {
420
for (int i = 0; i < arr.length; i++) {
521
int min = i;
@@ -13,6 +29,16 @@ public static void sort(int[] arr) {
1329
}
1430
}
1531

32+
/**
33+
* Utility method for swapping elements in an array.
34+
*
35+
* @param arr
36+
* is an array to be swapped
37+
* @param i
38+
* is index of first element
39+
* @param j
40+
* is index of second element
41+
*/
1642
private static void swap(int[] arr, int i, int j) {
1743
int temp = arr[i];
1844
arr[i] = arr[j];

0 commit comments

Comments
 (0)