Java Array Swap swap(int[] array, int i, int j)

Here you can find the source of swap(int[] array, int i, int j)

Description

swap

License

Open Source License

Declaration

public static void swap(int[] array, int i, int j) 

Method Source Code

//package com.java2s;

public class Main {
    public static void swap(byte[] data, int pos1, int pos2) {
        byte tmp = data[pos1];
        data[pos1] = data[pos2];//from   w ww.  j av a 2  s  . c om
        data[pos2] = tmp;
    }

    public static void swap(short[] data, int pos1, int pos2) {
        short tmp = data[pos1];
        data[pos1] = data[pos2];
        data[pos2] = tmp;
    }

    public static void swap(int[] array, int i, int j) {
        if (i == j)
            return;

        int old = array[i];
        array[i] = array[j];
        array[j] = old;
    }
}

Related

  1. swap(int[] arr, int a, int b)
  2. swap(int[] arr, int a, int b)
  3. swap(int[] arr, int a, int b, int c, int d, int key)
  4. swap(int[] arr, int i, int j)
  5. swap(int[] array)
  6. swap(int[] array, int idx1, int idx2)
  7. swap(int[] array, int index0, int index1)
  8. swap(int[] array, int x, int y)
  9. swap(int[] inArray, int index1, int index2)