MCPcopy Create free account
hub / github.com/TheAlgorithms/Java / swap

Method swap

src/main/java/com/thealgorithms/sorts/SortUtils.java:19–25  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.

Callers 15

testSwapMethod · 0.95
sortMethod · 0.95
bubbleSortMethod · 0.95
sortMethod · 0.95
dutchNationalFlagSortMethod · 0.95
partitionMethod · 0.95
heapSortMethod · 0.95
heapifyMethod · 0.95
doSortMethod · 0.95
sortMethod · 0.95
sortMethod · 0.95

Calls

no outgoing calls

Tested by 2

testSwapMethod · 0.76