Swaps two elements at the given positions in an array. @param array the array in which to swap elements @param i the index of the first element to swap @param j the index of the second element to swap @param the type of elements in the array
(T[] array, int i, int j)
| 17 | * @param <T> the type of elements in the array |
| 18 | */ |
| 19 | public static <T> void swap(T[] array, int i, int j) { |
| 20 | if (i != j) { |
| 21 | final T temp = array[i]; |
| 22 | array[i] = array[j]; |
| 23 | array[j] = temp; |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Compares two elements to see if the first is less than the second. |
no outgoing calls