File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change 88
99public class SelectionSort implements SortAlgorithm {
1010
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+
1122 /**
1223 * This method implements the Generic Selection Sort
1324 *
@@ -22,14 +33,14 @@ public <T extends Comparable<T>> T[] sort(T[] arr) {
2233 int min = i ;
2334
2435 for (int j = i + 1 ; j < n ; j ++) {
25- if (SortUtils . less (arr [j ], arr [ min ]) ) {
36+ if (arr [ min ]. compareTo (arr [j ]) < 0 ) {
2637 min = j ;
2738 }
2839 }
2940
3041 // Swapping if index of min is changed
3142 if (min != i ) {
32- SortUtils . swap (arr , i , min );
43+ swap (arr , i , min );
3344 }
3445 }
3546
You can’t perform that action at this time.
0 commit comments