File tree 1 file changed +13
-2
lines changed
1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change 8
8
9
9
public class SelectionSort implements SortAlgorithm {
10
10
11
+ /**
12
+ * This method swaps the two elements in the array
13
+ * @param arr, i, j The array for the swap and
14
+ the indexes of the to-swap elements
15
+ */
16
+ public void swap (T [] arr , int i , int j ) {
17
+ T temp = arr [i ];
18
+ arr [i ] = arr [j ];
19
+ arr [j ] = temp ;
20
+ }
21
+
11
22
/**
12
23
* This method implements the Generic Selection Sort
13
24
*
@@ -22,14 +33,14 @@ public <T extends Comparable<T>> T[] sort(T[] arr) {
22
33
int min = i ;
23
34
24
35
for (int j = i + 1 ; j < n ; j ++) {
25
- if (SortUtils . less (arr [j ], arr [ min ]) ) {
36
+ if (arr [ min ]. compareTo (arr [j ]) < 0 ) {
26
37
min = j ;
27
38
}
28
39
}
29
40
30
41
// Swapping if index of min is changed
31
42
if (min != i ) {
32
- SortUtils . swap (arr , i , min );
43
+ swap (arr , i , min );
33
44
}
34
45
}
35
46
You can’t perform that action at this time.
0 commit comments