List of utility methods to do Array Swap
void | swap(T[] array, int i, int len) swap T tmp = array[i]; array[i] = array[len - i - 1]; array[len - i - 1] = tmp; |
T[] | swap(T[] array, int indexOne, int indexTwo) Swaps elements in the array at indexOne and indexTwo. T elementAtIndexOne = array[indexOne];
array[indexOne] = array[indexTwo];
array[indexTwo] = elementAtIndexOne;
return array;
|
void | swap(T[] data, int a, int b) swap T temp = data[a]; data[a] = data[b]; data[b] = temp; |
void | swap(T[] elements, int i, int j) Swaps the array's elements. T element = elements[i]; elements[i] = elements[j]; elements[j] = element; |
void | swap(T[] ts, int i, int j) swap T tmp = ts[i]; ts[i] = ts[j]; ts[j] = tmp; |
void | swap2(double v[], int v2[], int i, int j) swap double tmp1; int tmp2; tmp1 = v[i]; v[i] = v[j]; v[j] = tmp1; tmp2 = v2[i]; v2[i] = v2[j]; v2[j] = tmp2; ... |
void | swap2Bytes(byte[] bytes, int offset) Swaps the 2 bytes (changes endianness) of the bytes at the given offset. swapBytesAt(bytes, offset + 0, offset + 1); |
void | swap3(String[] a, int x, int y, int z) Auxiliary method for sorting lexicographically the strings. String t = a[x]; a[x] = a[y]; a[y] = a[z]; a[z] = t; |
void | swapAll(final Object[] array) swap All Object tmp; for (int i = 0, j = array.length - 1; i < j; i++, j--) { tmp = array[i]; array[i] = array[j]; array[j] = tmp; |
void | swapAndPrint(int[] arr, int m, int n) swap And Print int temp = arr[m];
arr[m] = arr[n];
arr[n] = temp;
print(arr);
|