Java Array Swap swapPerTowElement(int[] arr)

Here you can find the source of swapPerTowElement(int[] arr)

Description

swap Per Tow Element

License

Open Source License

Declaration

private static void swapPerTowElement(int[] arr) 

Method Source Code

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

public class Main {

    private static void swapPerTowElement(int[] arr) {
        int len = arr.length;
        for (int i = 1; i < len; i += 2) {
            swap(arr, i, i - 1);//from   w w  w. j  av  a  2s.co m
        }
    }

    private static void swap(int[] arr, int i, int j) {
        int t = arr[i];
        arr[i] = arr[j];
        arr[j] = t;
    }
}

Related

  1. swapNumbers(int i, int j, double[] array)
  2. swapObjects(Object[] array, int a, int b)
  3. swapOrder16(byte[] buffer, int byteOffset, int sampleCount)
  4. swapOrder32(byte[] buffer, int byteOffset, int sampleCount)
  5. swapParallel(Object[] x, Object[] y, int a, int b, int yrel)
  6. swapReferences(Object[] a, int index1, int index2)
  7. swapRgbColorComponents(byte[] pixelArray)
  8. swapTokens(String grid[])
  9. swapValues(double[] arr, double v1, double v2)