Package net.algart.arrays
Class JArrays.IntAndIndexArrayExchanger
java.lang.Object
net.algart.arrays.JArrays.IntAndIndexArrayExchanger
- All Implemented Interfaces:
ArrayExchanger,ArrayExchanger32
- Enclosing class:
JArrays
Implementation of
ArrayExchanger, that simultaneously exchanges two pairs elements at the same
positions in two arrays: some int[] array and some int[] array.
It is convenient, when the 1st array contains data and the 2nd array contains some "indexes",
and we want to exchange indexes simultaneously with sorting the data array.-
Constructor Summary
ConstructorsConstructorDescriptionIntAndIndexArrayExchanger(int[] array, int[] indexes) Creates new exchanger, exchanging elements of both passed arrays. -
Method Summary
Modifier and TypeMethodDescriptionvoidswap(int first, int second) Exchanges two pair: 1) elements array[(int)first] and array[(int)second], 2) elements indexes[(int)first] and indexes[(int)second], where array and indexesare the arguments of the constructor.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.algart.arrays.ArrayExchanger32
swap
-
Constructor Details
-
IntAndIndexArrayExchanger
public IntAndIndexArrayExchanger(int[] array, int[] indexes) Creates new exchanger, exchanging elements of both passed arrays.- Parameters:
array- some Java array.indexes- another Java array.- Throws:
NullPointerException- if one of the arguments is null.
-
-
Method Details
-
swap
public void swap(int first, int second) Exchanges two pair: 1) elements array[(int)first] and array[(int)second], 2) elements indexes[(int)first] and indexes[(int)second], where array and indexesare the arguments of the constructor.- Specified by:
swapin interfaceArrayExchanger32- Parameters:
first- index of the first exchanged element.second- index of the second exchanged element.
-