Java Array Swap swap(int[] arr, int a, int b, int c, int d, int key)

Here you can find the source of swap(int[] arr, int a, int b, int c, int d, int key)

Description

swap

License

Open Source License

Declaration

public static void swap(int[] arr, int a, int b, int c, int d, int key) 

Method Source Code

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

public class Main {
    public static void swap(int[] arr, int a, int b, int c, int d, int key) {
        int temp;
        switch (key) {
        case 0:/* ww  w.j a v a2  s . c  o  m*/
            temp = arr[d];
            arr[d] = arr[c];
            arr[c] = arr[b];
            arr[b] = arr[a];
            arr[a] = temp;
            return;
        case 1:
            temp = arr[a];
            arr[a] = arr[c];
            arr[c] = temp;
            temp = arr[b];
            arr[b] = arr[d];
            arr[d] = temp;
            return;
        case 2:
            temp = arr[a];
            arr[a] = arr[b];
            arr[b] = arr[c];
            arr[c] = arr[d];
            arr[d] = temp;
            return;
        }
    }

    public static void swap(byte[] arr, int a, int b, int c, int d, int key) {
        byte temp;
        switch (key) {
        case 0:
            temp = arr[d];
            arr[d] = arr[c];
            arr[c] = arr[b];
            arr[b] = arr[a];
            arr[a] = temp;
            return;
        case 1:
            temp = arr[a];
            arr[a] = arr[c];
            arr[c] = temp;
            temp = arr[b];
            arr[b] = arr[d];
            arr[d] = temp;
            return;
        case 2:
            temp = arr[a];
            arr[a] = arr[b];
            arr[b] = arr[c];
            arr[c] = arr[d];
            arr[d] = temp;
            return;
        }
    }
}

Related

  1. swap(int keys[], int values[], int a, int b)
  2. swap(int[] a, int first, int second)
  3. swap(int[] a, int i, int j)
  4. swap(int[] arr, int a, int b)
  5. swap(int[] arr, int a, int b)
  6. swap(int[] arr, int i, int j)
  7. swap(int[] array)
  8. swap(int[] array, int i, int j)
  9. swap(int[] array, int idx1, int idx2)