Java Array Swap swap(long[] keys, double[] values, int i, int j)

Here you can find the source of swap(long[] keys, double[] values, int i, int j)

Description

Swaps the keys and values at i with those at j

License

Open Source License

Parameter

Parameter Description
keys a parameter
values a parameter
i a parameter
j a parameter

Declaration

private static final void swap(long[] keys, double[] values, int i, int j) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//www .j  a v  a  2 s .co  m
     * Swaps the keys and values at {@code i} with those at {@code j}
     * 
     * @param keys
     * @param values
     * @param i
     * @param j
     */
    private static final void swap(long[] keys, double[] values, int i, int j) {
        long keySwap = keys[i];
        keys[i] = keys[j];
        keys[j] = keySwap;

        double swapValue = values[i];
        values[i] = values[j];
        values[j] = swapValue;
    }

    /**
     * Swaps the keys and values at {@code i} with those at {@code j}
     * 
     * @param keys
     * @param values
     * @param i
     * @param j
     */
    private static final void swap(int[] keys, int[] values, int i, int j) {
        int keySwap = keys[i];
        keys[i] = keys[j];
        keys[j] = keySwap;

        int swapValue = values[i];
        values[i] = values[j];
        values[j] = swapValue;
    }

    /**
     * Swaps the keys and values at {@code i} with those at {@code j}
     * 
     * @param keys
     * @param values
     * @param i
     * @param j
     */
    private static final <T> void swap(int[] keys, T[] values, int i, int j) {
        int keySwap = keys[i];
        keys[i] = keys[j];
        keys[j] = keySwap;

        T swapValue = values[i];
        values[i] = values[j];
        values[j] = swapValue;
    }

    /**
     * Swaps the keys and values at {@code i} with those at {@code j}
     * 
     * @param keys
     * @param values
     * @param i
     * @param j
     */
    private static final void swap(int[] keys, Object[][] values, int i, int j) {
        int keySwap = keys[i];
        keys[i] = keys[j];
        keys[j] = keySwap;

        Object swapValue;
        for (int k = 0; k < values.length; k++) {
            swapValue = values[k][i];
            values[k][i] = values[k][j];
            values[k][j] = swapValue;
        }
    }

    /**
     * Swaps the keys and values at {@code i} with those at {@code j}
     * 
     * @param keys
     * @param values
     * @param i
     * @param j
     */
    private static final <T> void swap(long[] keys, T[] values, double[] probs, int i, int j) {
        long keySwap = keys[i];
        keys[i] = keys[j];
        keys[j] = keySwap;

        T swapValue = values[i];
        values[i] = values[j];
        values[j] = swapValue;

        double swapProb = probs[i];
        probs[i] = probs[j];
        probs[j] = swapProb;
    }
}

Related

  1. swap(int[] array, int x, int y)
  2. swap(int[] inArray, int index1, int index2)
  3. swap(int[] integers, int positionX, int positionY)
  4. swap(int[] list, int i, int j)
  5. swap(long[] a, int i, int change)
  6. swap(Object aobj[], int i, int j, int k)
  7. swap(Object[] arr, int a, int b)
  8. swap(Object[] arr, int i, int j)
  9. swap(Object[] arr, int i, int j)